问题 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;
}

2014辽宁ACM省赛 Prime Factors的更多相关文章

  1. Graph(2014辽宁ACM省赛)

    问题 F: Graph 时间限制: 1 Sec  内存限制: 128 MB 提交: 30  解决: 5 [cid=1073&pid=5&langmask=0" style=& ...

  2. 2014 ACM省赛总结

    今年ACM省赛已经过去一个星期左右了,2年的ACM训练是该做个总结了,因为前几日去參加蓝桥杯总决赛,所以没来的及写总结,如今在这小小总结一下吧-- 依晰记得去年省赛时候的样子,如今感觉那时像是个无知的 ...

  3. 第六届acm省赛总结(退役贴)

    前言: 这是我的退役贴,之前发到了空间里,突然想到也要在博客里发一篇,虽然我很弱,但是要离开了还是有些感触,写出来和大家分享一下,希望不要见笑.回来看看,这里也好久没有更新了,这一年确实有些懈怠,解题 ...

  4. [CareerCup] 7.7 The Number with Only Prime Factors 只有质数因子的数字

    7.7 Design an algorithm to find the kth number such that the only prime factors are 3,5, and 7. 这道题跟 ...

  5. [原]sdut2624 Contest Print Server (大水+大坑)山东省第四届ACM省赛

    本文出自:http://blog.csdn.net/svitter 原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&am ...

  6. 1059. Prime Factors (25)

    时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given any positive integer N, y ...

  7. PAT 1059. Prime Factors (25) 质因子分解

    题目链接 http://www.patest.cn/contests/pat-a-practise/1059 Given any positive integer N, you are suppose ...

  8. PAT1059:Prime Factors

    1059. Prime Factors (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...

  9. A1059. Prime Factors

    Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...

随机推荐

  1. MyBatis一级缓存引起的无穷递归

    MyBatis一级缓存引起的无穷递归 引言: 最近在项目中参与了一个领取优惠劵的活动,当多个用户领取同一张优惠劵的时候,使用了数据库锁控制并发,起初的设想是:如果多个人同时领一张劵,第一个到达的人领取 ...

  2. 让ecshop显示商品销量或者月销量

    首先,ecshop的信息显示模块在. ./includes/lib_goods.php文件 在其末尾添加下面这个函数 月销量:(和总销量二选一) function ec_buysum($goods_i ...

  3. 在html中禁用自己主动完毕

    输入框输入内容时总是显示历史输入历史记录,现禁用的方法是加入一个属性: <input type="text name="txt_xm" autocomplete=& ...

  4. windows phone (21) Grid元素的Background和Clip

    原文:windows phone (21) Grid元素的Background和Clip Grid是唯一可以在内部定制单元格的panel类,我们可以在grid中定制单元格,然后通过grid.row和g ...

  5. Naive Bayes Classification

    Maching Learning QQ群:2 请说明来自csdn 微信:soledede

  6. [原创]如何编写多个阻塞队列连接下的多生产者多消费者的Python程序

    平常在写程序时,往往会遇到一个需求:在程序的多个阶段都会出现阻塞的可能,因此,这多个阶段就需要并发执行. Python的多线程有一个特点,就是不允许从外部结束一个运行中的线程,这给我们编写代码时带来了 ...

  7. hdu 4444 Walk (离散化+建图+bfs+三维判重 好题)

    Walk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submi ...

  8. 询url包括字符串参数(js高度注意事项)

    以防万一  url="http://write.blog.csdn.net/postedit? id=5&search=ok" function getArgs() { v ...

  9. LVM逻辑卷管理@设备、格式、摩、引导自己主动安装一个完整的章节

    离http://www.it165.net/admin/html/201307/1553.html LVM的重要性,在这里我也就不多说了,今天和大家分享一下.LVM设备,而且安装方式. 首先呢,先让我 ...

  10. Java Swing 绝对布局管理方法,null布局(转)

    首先把相关容器的布局方式设为 setLayout(null); 然后调用组件的  setBounds() 方法 设置button的位置为(100,100) 长宽分别为 60,25 jButton.se ...