Eddy's research I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5098 Accepted Submission(s): 3056
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
Author
eddy
Recommend
JGShining
将一个数分解成一个素数相乘的形式
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int n;
int a[65536];
int b[100];
int i,j,k;
memset(a,0,sizeof(a));
a[0]=a[1]=1;
for(i=2;i<65536;i++)
{
if(!a[i])
for(j=i*2;j<65536;j+=i)
a[j]=1;
}
while(cin>>n)
{
for(i=2,k=0;i<65536&&n;)
{
if(!a[i])
{
if(n%i==0)
{
b[k++]=i;
n/=i;
i=2;
}
else i++;
}
else i++;
}
for(i=0;i<k;i++)
if(i==k-1)
cout<<b[i]<<endl;
else
cout<<b[i]<<"*";
}
return 0;
}
本文介绍了一个用于将整数分解为其素数因子的算法,并提供了完整的C++实现代码。该算法适用于1到65535之间的整数,通过标记法快速找出素数因子。
1006

被折叠的 条评论
为什么被折叠?



