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): 2486 Accepted Submission(s): 1527


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
素数筛选:对于素数筛选的几种方法,日后再做总结。这样不用每次回顾时想半天了。。
 1 #include<stdio.h>
2 #include<string.h>
3 #define MAX 65543
4 bool flag[MAX] ;
5 int prime[MAX/2] ;
6 void get_prime( int &k )
7 {
8 memset(flag , true , sizeof (flag) ) ;
9 int i , j ;
10 for ( i = 2 ; i < MAX ; i ++ )
11 {
12 if ( flag[i] ) prime[k++] = i ;
13 for ( j = 0 ; j < k && i * prime[j] < MAX ; j ++ )
14 {
15 flag [i*prime[j]] = false ;
16 if ( i % prime[j] == 0 ) break ;
17 }
18 }
19 }
20
21 int main ()
22 {
23 int n , k = 0 ;
24 get_prime(k) ;
25 while ( scanf ( "%d" , &n ) != EOF )
26 {
27 int i ;
28 bool first = true ;
29 for ( i = 0 ; i < k ; i ++ )
30 {
31 while ( n % prime[i] == 0 )
32 {
33 if ( first )
34 {
35 printf ( "%d" , prime[i] ) ;
36 first = false ;
37 }
38 else printf ( "*%d" , prime[i] ) ;
39 n /= prime[i] ;
40 }
41 }
42 printf("\n");
43 }
44 return 0 ;
45 }

  

 
posted @ 2011-08-09 15:05  贺佐安  阅读(691)  评论(0编辑  收藏  举报