您的位置:首页 > 其它

【hdu - 1164 Eddy's research I】

2012-07-08 21:17 260 查看

Eddy's research I

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3554 Accepted Submission(s): 2182


[align=left]Problem Description[/align]
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 .

[align=left]Input[/align]
The input will contain a number 1 < x<= 65535 per line representing the number of elements of the set.

[align=left]Output[/align]
You have to print a line in the output for each entry with the answer to the previous question.

[align=left]Sample Input[/align]

11
9412

[align=left]Sample Output[/align]

11
2*2*13*181

[align=left]Author[/align]
eddy

[align=left]Recommend[/align]
JGShining

// Project name : 1164 ( Eddy's research I )
// File name    : main.cpp
// Author       : Izumu
// Date & Time  : Sun Jul  8 21:07:17 2012

#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

int main()
{
int num;
while (cin >> num)
{
int* prime;
prime =new int[1000];
int top = -1;
int current_prime = 2;

int CGetNextPrime(int);

while (num != 1)
{
if (num % current_prime == 0)
{
top++;
prime[top] = current_prime;
num /= current_prime;
}
else
{
current_prime = CGetNextPrime(current_prime);
}
}

// output
for (int i = 0; i < top; i++)
{
cout << prime[i] << "*";
}
cout << prime[top] << endl;

}
return 0;
}
/*********************************************************************/
bool CIsPrime(int k)
{
int stop = sqrt(k);
bool yes = true;
for (int i = 2; yes && i <= stop; i++)
{
if (k % i == 0)
{
yes = false;
}
}
return yes;
}
/*********************************************************************/
int CGetNextPrime(int num)
{
num++;
while (!CIsPrime(num))
{
num++;
}
return num;
}
// end
// ism
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: