Eddy's interest is very extensive, recently he is interested in prime number. Eddy discover the all number owned can be divided into the multiply of prime number, but he can't write program, so Eddy has to ask intelligent you to help him, he asks you to write a program which can do the number to divided into the multiply of prime number factor .
Input
The input will contain a number 1 < x<= 65535 per line representing the number of elements of the set.
Output
You have to print a line in the output for each entry with the answer to the previous question.
Sample Input
11 9412
Sample Output
11 2*2*13*181
/*
题意:判断N是否是素数,如果是,直接输出,否则,分解成以素数之积的形式输出;
解题报告: 由于给定的N最大不到70000,打素数表,在遍历一遍就OK了。
*/
标程:
#include<stdio.h> #include<string.h> #include<math.h> #define pi 70000 int prm[pi+10],is[pi],a[10000]; int getprm() { int i,j,k=0; int s,e=(int)sqrt(pi+0.0); memset(is,1,sizeof(is)); prm[k++]=2,is[0]=is[1]=0; for(i=4;i<pi;i+=2) is[i]=0; for(i=3;i<e;i+=2) if(is[i]) { prm[k++]=i; for(s=2*i,j=i*i;j<pi;j+=i) is[j]=0; } for(;i<pi;i+=2) if(is[i]) prm[k++]=i; return k; } int main() { //freopen("a.txt","r",stdin); int i,n; int t=getprm(); while(scanf("%d",&n)!=EOF) { int j=0; if(n==1) { printf("1\n"); continue; } memset(a,0,sizeof(a)); for(i=0;i<t && prm[i]<n+10;i++) if(n%prm[i]==0) { n/=prm[i]; a[j++]=prm[i]; i--; } if(j<=1) printf("%d\n",a[0]); else { for(i=0;i<j-1;i++) printf("%d*",a[i]); printf("%d\n",a[j-1]); } } return 0; }