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 @   贺佐安  阅读(700)  评论(0编辑  收藏  举报
编辑推荐:
· 现代计算机视觉入门之:什么是视频
· 你所不知道的 C/C++ 宏知识
· 聊一聊 操作系统蓝屏 c0000102 的故障分析
· SQL Server 内存占用高分析
· .NET Core GC计划阶段(plan_phase)底层原理浅谈
阅读排行:
· 我干了两个月的大项目,开源了!
· 千万级的大表,如何做性能调优?
· 盘点!HelloGitHub 年度热门开源项目
· Phi小模型开发教程:用C#开发本地部署AI聊天工具,只需CPU,不需要GPU,3G内存就可以运行,
· 你所不知道的 C/C++ 宏知识——基于《C/C++ 宏编程的艺术》
点击右上角即可分享
微信分享提示