Almost Prime
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive.
Input contains one integer number n (1 ≤ n ≤ 3000).
Output the amount of almost prime numbers between 1 and n, inclusive.
| input |
| 10 |
| output |
| 2 |
| input |
| 21 |
| output |
| 8 |
#include <iostream>
#include <cstdio> using namespace std;
//计算数字n不同素因子个数
int distinctPrime (int n); int main()
{
int n, i, counter = ;
cin >> n;
for(i=; i<=n; i++){
if(distinctPrime(i) == )
counter ++;
}
cout << counter <<endl;
return ;
} int distinctPrime (int n) {
int i, t, flag, counter = ;
for(i=, t=n; i<n; i++) {
while(t>) {
if(t%i==)
t = t/i;
else
break;
flag = ;
}
if(flag)
counter++;
flag = ;
}
return counter;
}
Almost Prime的更多相关文章
- Java 素数 prime numbers-LeetCode 204
Description: Count the number of prime numbers less than a non-negative number, n click to show more ...
- Prime Generator
Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- UVa 524 Prime Ring Problem(回溯法)
传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbe ...
- Sicily 1444: Prime Path(BFS)
题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...
- hdu 5901 count prime & code vs 3223 素数密度
hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem ...
- 最小生成树 prime zoj1586
题意:在n个星球,每2个星球之间的联通需要依靠一个网络适配器,每个星球喜欢的网络适配器的价钱不同,先给你一个n,然后n个数,代表第i个星球喜爱的网络适配器的价钱,然后给出一个矩阵M[i][j]代表第i ...
- 最小生成树 prime poj1258
题意:给你一个矩阵M[i][j]表示i到j的距离 求最小生成树 思路:裸最小生成树 prime就可以了 最小生成树专题 AC代码: #include "iostream" #inc ...
- 最小生成树 prime + 队列优化
存图方式 最小生成树prime+队列优化 优化后时间复杂度是O(m*lgm) m为边数 优化后简直神速,应该说对于绝大多数的题目来说都够用了 具体有多快呢 请参照这篇博客:堆排序 Heapsort / ...
- 最小生成树 prime poj1287
poj1287 裸最小生成树 代码 #include "map" #include "queue" #include "math.h" #i ...
随机推荐
- Perfect Squares
Perfect Squares Total Accepted: 18854 Total Submissions: 63048 Difficulty: Medium Given a positive i ...
- spring下配置dbcp,c3p0,proxool[转]
不管通过何种持久化技术,都必须通过数据连接访问数据库,在Spring中,数据连接是通过数据源获得的.在以往的应用中,数据源一般是Web应用服务器提供的.在Spring中,你不但可以通过JNDI获取应用 ...
- 通过Wmi实现Hyper-V远程管理(一)
最近公司需要做Hyper-V的远程管理,在现有产品基础上扩展对Hyper V的管理,实现远程开关机.远程开启虚拟机会话,其他内容可查看MSDN中有对Hyper-V的描述和相关实例代码. Wmi操作hy ...
- python 序列类型
1.不可变的序列类型:tuple.range.str.set 001:对于tuple 类型有如下几种构造方式 1.() 构造一个空的元组. 2.a | (a,) 构造一个只有一个元素的元组. 3.tu ...
- SQL Server 的 6 种隔离级别
背景知识: 高并发一直以来是数据的所追求的目标,然,一般事物是有两面性的.不多说了,等下变邪教了.下面直接看 并发性最高的隔离级别 read uncommitted 1. read uncommitt ...
- USB interrupt传输和isochronous传输的区别
一直没理解USB的iso传输和interrupt传输的区别. 后来仔细看了下USB2.0 SPEC后才明白. interrupt传输和iso传输,都是等时的传输,也就是某个时间间隔发送一次. 区别在于 ...
- 去掉ExpandableListView的箭头图标
到ExpandableListView时有个箭头图标系统自带的在你自定义布局也不能去掉只要设置一个属性即可,如下: settingLists.setGroupIndicator(null); ~~~ ...
- URAL 2025. Line Fighting (math)
2025. Line Fighting Time limit: 1.0 second Memory limit: 64 MB Boxing, karate, sambo- The audience i ...
- C# Web对文件的管理
/// <summary> /// 创建新文件 /// </summary> /// <param name="parentPath">文件路径 ...
- servlet+ajax+json字符串后台传入,前端解析并把数据循环填入表格实例
写在前面:1.源代码来源于博客http://blog.sina.com.cn/u/2904067371 ,在此基础上对于前端代码稍作更改,把传过来的数据解析并传入表格2.json解析,用eval()3 ...