hdu 1405
2015-08-19 15:55
225 查看
Description
Tomorrow is contest day, Are you all ready?
We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with many excellent boys who have no chance to attend the Province-Final.
Now, your task is relaxing yourself and making the last practice. I guess that at least there are 2 problems which are easier than this problem.
what does this problem describe?
Give you a positive integer, please split it to some prime numbers, and you can got it through sample input and sample output.
Input
Input file contains multiple test case, each case consists of a positive integer n(1<n<65536), one per line. a negative terminates the input, and it should not to be processed.
Output
For each test case you should output its factor as sample output (prime factor must come forth ascending ), there is a blank line between outputs.
Sample Input
60
12
-1
Sample Output
Case 1.
2 2 3 1 5 1
Case 2.
2 2 3 1
Hint
题意:
给你一个正整数n(1<n<65536),把它进行质因数分解,例如题目所给的两个案例60=2^2*3^1*5^1,所以要输出2,2,3,1,5,1,12=2^2*3^1,所以要输出2,2,3,1,输入包含多组案例,当输入一个负数的是时候表示不再输入,结束程序。
思路:
先判断2是不是n的质因数,当判断是质因数的时候就要统计要他的歌数,用count统计起来。然后从3开始循环到n,逐个判断是不是n的质因子,如果是就同理用count统计起来,但是循环的时候i+=2就好了,这个题目要注意最后一个输出也有空格,被坑在这里了。。。。
代码:
Tomorrow is contest day, Are you all ready?
We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with many excellent boys who have no chance to attend the Province-Final.
Now, your task is relaxing yourself and making the last practice. I guess that at least there are 2 problems which are easier than this problem.
what does this problem describe?
Give you a positive integer, please split it to some prime numbers, and you can got it through sample input and sample output.
Input
Input file contains multiple test case, each case consists of a positive integer n(1<n<65536), one per line. a negative terminates the input, and it should not to be processed.
Output
For each test case you should output its factor as sample output (prime factor must come forth ascending ), there is a blank line between outputs.
Sample Input
60
12
-1
Sample Output
Case 1.
2 2 3 1 5 1
Case 2.
2 2 3 1
Hint
60=2^2*3^1*5^1
题意:
给你一个正整数n(1<n<65536),把它进行质因数分解,例如题目所给的两个案例60=2^2*3^1*5^1,所以要输出2,2,3,1,5,1,12=2^2*3^1,所以要输出2,2,3,1,输入包含多组案例,当输入一个负数的是时候表示不再输入,结束程序。
思路:
先判断2是不是n的质因数,当判断是质因数的时候就要统计要他的歌数,用count统计起来。然后从3开始循环到n,逐个判断是不是n的质因子,如果是就同理用count统计起来,但是循环的时候i+=2就好了,这个题目要注意最后一个输出也有空格,被坑在这里了。。。。
代码:
#include<cstdio> #include<cmath> #include<cstring> using namespace std; int main() { int n; int casex=1,count; while(scanf("%d",&n)&&n>0) { if(casex!=1) printf("\n"); count=0; printf("Case %d.\n",casex++); if(n%2==0) { printf("2 "); while(n%2==0) { count++; n/=2; } printf("%d ",count); } for(int i=3; i<=n; i+=2) { count=0; if(n%i==0) { printf("%d ",i); while(n%i==0) 4000 { count++; n/=i; } printf("%d ",count); } } printf("\n"); } return 0; }
相关文章推荐
- c++ primer plus 第八章《编程题8.8.5》
- 小P的故事——神奇的换零钱
- (转载)KL距离
- 动态计算cell高度(1)
- java并发编程-Executor框架
- 关于Bean的知识private static final long serialVersionUID = 1L
- 常见26个jquery使用技巧详解(比如禁止右键点击、隐藏文本框文字等)
- C-1 九九乘法表
- 我的eclipse插件推荐
- 用CImage类来显示PNG、JPG等图片
- Android(java)学习笔记178:BroadcastReceiver之 自定义广播
- OpenGL ES 2.0 系列一
- HDU 1158 Employment Planning
- scala学习第二章 控制结构与函数
- poj1860 最短路 无限增大环
- QNetAccessManager http请求
- Using mysql as Nosql ------------- Mysql HandlerSockets使用
- 4.3 现在可用的客体类有哪些呢
- SuperMapPy 批量拼接 GeoTiff影像
- 挣值管理 EVM