2014辽宁ACM省赛 Prime Factors
来源:互联网 发布:android 移动网络权限 编辑:程序博客网 时间:2024/05/03 15:38
问题 L: Prime Factors
时间限制: 1 Sec 内存限制: 128 MB
提交: 36 解决: 28
[提交][状态][论坛]
题目描述
I'll give you a number , please tell me how many different prime factors in this number.
输入
There is multiple test cases , in each test case there is only one line contains a number N(2<=N<=100000). Process to the end of file.
输出
For each test case , output one line contains one number , indicating different prime factor in the number N.
样例输入
12 5 30
样例输出
2 1 3
提示
12 = 2 * 2 * 3
5 = 5
30 = 2 * 3 * 5
水题一道,打表,枚举质因子就完了。
#include<iostream>#include<algorithm>#include<cstdio>#include<cmath>#include<vector>using namespace std;const int MAX=100000;vector<int> f;void init(){ int k=0; for(int i=2;i<=MAX;i++) { bool flag=true; for(int j=2;j<=sqrt(i);j++) { if(i%j==0) { flag=false; break; } } if(flag) f.push_back(i); }}int main(){ init(); int n; while(cin>>n) { int cnt=0; for(int i=0;i<f.size();i++) { if(n%f[i]==0) { cnt++; n/=f[i]; while(n%f[i]==0) { n/=f[i]; } } } cout<<cnt<<endl; } return 0;}
1 0
- 2014辽宁ACM省赛 Prime Factors
- 2014ACM辽宁省赛Prime Factors
- 2014辽宁ACM省赛 Guess
- 2014辽宁ACM省赛 Distance
- Graph(2014辽宁ACM省赛)
- 2014辽宁ACM省赛 Lucky Numbers
- Prime Factors
- Prime Factors
- Prime Factors
- Prime Factors
- 2014 辽宁 ACM 省赛 ( kuangbin oj 1020)|| Distance(两点式直线公式或直线求交点
- UVa 583-Prime Factors
- 1059. Prime Factors
- PAT_1059: Prime Factors
- UVa 583 - Prime Factors
- 1059. Prime Factors (25)
- 1059. Prime Factors (25)
- PAT 1059. Prime Factors
- The connection to adb is down, and a severe error has occured.问题解决办法
- 云计算
- 【Linux驱动】TQ2440 DM9000E网卡驱动移植(Linux-2.6.30.4)
- Java 理论与实践: JDK 5.0 中更灵活、更具可伸缩性的锁定机制
- ZOJ-2706
- 2014辽宁ACM省赛 Prime Factors
- linux下多进程/多线程编程总结
- 智力面试题1-找出25匹马的前三名
- CSS控制样式
- jQuery Easing 运动效果插件 easing.js
- 2014百度之星资格赛——Labyrinth
- Struts2框架中书写XML配置文件时能添加提示技巧(方案二)
- Reverse Linked List II
- 应用服务器