Eddy's research I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5201 Accepted Submission(s): 3127
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<iostream>
#include <cstdio>
#include<cstring>
#include<algorithm>
#include <cmath>
using namespace std;
int main()
{
int x,i,j,a[10000],b[1002];
memset(a,0,sizeof(a));
for(i=2;i<10000;i++)
for(j=i*2;j<10000;j+=i)
a[j]=1;
while(~scanf("%d",&x))
{
int t=0,s=x;
for(i=2;i<=1000&&x!=1;i++)
{
if(a[i]==0&&x%i==0)
while(x%i==0)
{
b[t++]=i;
x/=i;
}
}
if(x==1)
{
for(i=0;i<t-1;i++)
printf("%d*",b[i]);
printf("%d\n",b[t-1]);
}
else
{
for(i=0;i<=t-1;i++)
printf("%d*",b[i]);
printf("%d\n",x);
}
}
return 0;
}