toj1868 Count the factors
来源:互联网 发布:excel数据如何恢复 编辑:程序博客网 时间:2024/05/18 02:41
题目链接:http://acm.tju.edu.cn/toj/showp1868.html
题目大意:求一个数的质因数个数
思路:这种题该堪称模板类题目,应该熟练写出来才对
代码:
//质因数的个数,只需要看2到sqrt(n)之间的质因数个数,若最后tmp>1说明sqrt(n)到n之间还有一个质数
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int i,j,n,ans;
while(cin>>n)
{
if(n==0)break;
ans=0;
int tmp=n;
for(i=2;i<sqrt(n);i++)
{
if(tmp%i==0)
{
ans++;
while(tmp%i==0)//i是它的质因数那么n/i也是一个因数,再分解n/i 比如2 4 6 8 是16的因数 但我们只要2就可以了
tmp/=i;
}
}
if(tmp>1)ans++;// sqrt(n)到n之间还有一个质因数
cout<<n<<" : "<<ans<<endl;
}
return 0;
}
- toj1868 Count the factors
- 10699 - Count the factors
- TJU Count the factors
- UVa 10699 - Count the factors
- TOJ 1868.Count the factors(埃式筛法)
- Find factors' count of a Number
- Finding the factors of an integer
- Getting the CPU count
- hdu3336 Count the string
- 【線段樹】Count the Colors
- UVa10007 - Count the Trees
- hdu3336 Count the string
- Count the colors
- ZOJ1610-Count the Colors
- zoj1610-Count the Colors
- HDU3336:Count the string
- ZOJ1610 Count the Colors
- Count the Colors
- 宏定义
- 链表的操作
- 黑马程序员------集合框架(No.2)(ArrayList、LinkedList、vector)
- ESAPI之会话安全
- HDU4745 Two Rabbits
- toj1868 Count the factors
- 聚类算法(待补充)
- 写在开博前的话
- 安装配置Oracle10g透明网关(Gateway For Sql Server)
- Linux内核进程管理-do_fork()执行过程分析
- 关于文件结束符EOF
- 一个合格的程序员应该读过哪些书
- JEECMS搜素引擎
- IOS第三十五天——使用ZXing开发二维码