|
|
вернуться в форумhelp wrong answer test #8 Послано jxhuzs 3 апр 2012 14:38 I use long long int with MinGW and have right answer for the input of 1000000000.Why it is still wrong? Here is my C code. #include<stdio.h> #include<math.h> #include<stdlib.h> int sum(int a); int main() { int count[10],i,j,base=0; //use count[2] to count [9] to store the number of digits long long int n,product=0; for(i=0;i<10;i++) count[i]=0; scanf("%lld",&n); if(n==1) printf("%d\n",1); else if(n==0) printf("%d\n",10); else{ for(i=9;i>1;i--){ while(n%i==0){ n/=i; count[i]++; } } if(n==1){ /* for(i=2;i<=9;i++){ for(j=0;j<count[i];j++){ printf("%d",i); } } */ for(i=9;i>=2;i--){ product=product+i*sum(count[i])*pow(10,base); base=base+count[i]; } printf("%lld",product); } else printf("%d",-1); printf("\n"); } system("pause"); return 0; } int sum(int a) { int term=1,i,result=0; for(i=0;i<a;i++){ result+=term; term*=10; } return result; }
|
|
|