hdu 1164 Eddy's research I

Eddy's research I

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


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
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 using namespace std;
 6 const int maxn = 65535;
 7 int prime[maxn];
 8 int main(void){
 9 #ifndef ONLINE_JUDGE
10   freopen("1164.in", "r", stdin);
11 #endif
12   memset(prime, 0, sizeof(prime));
13   for (int i = 2; i * i <= maxn; ++i)
14     if (prime[i] == 0)
15       for (int j = i*2; j <= maxn; j+=i)
16         prime[j] = 1;
17   int n; 
18 //  for (int i = 2; i < 100; ++i) if (!prime[i]) printf("%d ", i);
19   while (~scanf("%d", &n)){
20     bool flag = true;
21       while(n != 1){
22       for (int i = 2; i <= maxn; ++i){
23         while (!prime[i] && !(n%i)){
24           n = n / i; 
25           if (flag) printf("%d", i);
26           else printf("*%d", i);
27           flag = false;
28         }
29         if (n == 1) break;
30       }
31     }
32       printf("\n");
33   }
34 
35   return 0;
36 }

开始打素数表的时候打错了……

posted on 2013-03-12 21:21  aries__liu  阅读(150)  评论(0编辑  收藏  举报