#include<stdio.h> #include<math.h> int main() { int n; while(scanf("%d",&n)==1) { if(n==0) break; int num1[3000],lnum1=1,i,j,k,l,m,r=0,prime[100],lprime=0; int num2[100],lnum2=0,div[1000],ldiv=0,count=0; num1[0]=1; for(i=2;i<=n;i++) { for(j=0;j<lnum1;j++) { m=(num1[j]*i+r)%10; r=(num1[j]*i+r)/10; num1[j]=m; } while(r!=0) { num1[lnum1++]=r%10; r=r/10; } } for(i=2;i<=n;i++) { m=0; for(j=2;j<=sqrt(i);j++) { if(i%j==0) m++; } if(m==0) { prime[lprime++]=i; } } ldiv=0; for(i=lnum1-1;i>=0;i--) { div[ldiv++]=num1[i]; } count=0; for(i=0;i<lprime;i++) { k=0;r=0;lnum1=0; for(j=0;j<ldiv;j++) { m=(div[j]+r*10)/prime[i]; r=(div[j]+r*10)%prime[i]; if(m>0) { k=1; } if(k==1) { num1[lnum1++]=m; } } if(r==0) { count++; i=i-1; ldiv=0; for(j=0;j<lnum1;j++) { div[ldiv++]=num1[j]; } } else { num2[lnum2++]=count; count=0; } } printf("%3d! =",n); j=0; for(i=0;i<lnum2;i++) { if(j>14) { printf("\n "); j=0; } j++; printf("%3d",num2[i]); }printf("\n"); } return 0; }
Tuesday, October 4, 2011
uva : 160 - Factors and Factorials
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment