以下是我的程式碼,前面除2,除3還可以,但不知為何for迴圈以後的部分總是怪怪的...
#include
#include
#include
int main()
{
unsigned long long int n,r,k,j,q,i;
int pow;
j=i+1;
q=i+5;
r=2;
k=3;
begin:
pow=0;
scanf("%I64d",&n);
int tme,duration;
tme = clock();
//除2
while(!(n%2)){
n=n/2;
pow++;
}
if(pow)printf("%I64d(^%d)*",r,pow);
if(n==1)printf("\b ");
//除3
pow=0;
while(!(n%3)){
n=n/3;
pow++;
}
if(pow)printf("%I64d(^%d)*",k,pow);
if(n==1)printf("\b ");
for(int i=6;;i+=6) {
//除 7,13...
pow=0;
while(!(n%j)){
n=n/j;
pow++;
}
if(pow)printf("%I64d(^%d)*",j,pow);
if(n==1){printf("\b ");break;}
//除 11,17...
pow=0;
while(!(n%q)){
n=n/q;
pow++;
}
if(pow)printf("%I64d(^%d)*",q,pow);
if(n==1){printf("\b ");break;};}
printf("\n");
duration = clock()-tme;
printf( "\n%d milliseconds.\n", duration); system("pause");
goto begin;
}
This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.
留言列表