您的位置:首页 > 其它

Eddy's research I

2015-08-13 15:42 381 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1164


Eddy's research I

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 7641 Accepted Submission(s): 4645



Problem Description

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


打一个素数表,然后跑一遍素数表就可以了

#include <cstdio>
int prim[7000];
int main()
{
int j=1,k;
prim[0]=2;
for(int i=3;i<=65535;i+=2){
for(k=0;k<j;k++){
if(i%prim[k]==0)break;
}
if(k==j)prim[j++]=i;
}
int n,ans[1000];
while(scanf("%d",&n)!=EOF){
int m=0,i=0;
while(n!=prim[m]){
if(n%prim[m]==0){
ans[i++]=prim[m];
n/=prim[m];
continue;
}
else m++;
}
ans[i++]=prim[m];
printf("%d",ans[0]);
for(m=1;m<i;m++)
printf("*%d",ans[m]);
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: