CF 26A-Almost prime
来源:互联网 发布:预防网络成瘾的方法 编辑:程序博客网 时间:2024/06/03 07:31
Almost Prime
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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 andn, inclusive.
Input
Input contains one integer number n (1 ≤ n ≤ 3000).
Output
Output the amount of almost prime numbers between 1 and n, inclusive.
Sample Input
Input
10
Output
2
Input
21
Output
8
思路:
由给出的范围可得素数范围:0~1500 (3000/2=1500);
筛法得到0~x/2(x为所给值)之间的素数;
理解题意:题目要求的一类殆素数的特征是:仅由两个素数通过乘积或乘方变化的来 因此按序模素数只有两个能被整除则说明该数符合题意,ans++;
#include<cstdio>#include<iostream>using namespace std;int prime[1501];int main(){int x;while(scanf("%d",&x)!=EOF){int i,j;prime[0]=0;prime[1]=0;for(i=2;i<x/2+1;i++) prime[i]=1;for(i=1;i<x/2;i++){if(prime[i]) for(j=2*i;j<x/2+1;j+=i) prime[j]=0; }int num,count,ans=0;for(num=6;num<=x;num++){count=0;for(j=0;j<num/2+1;j++) { if(prime[j]==0)continue; if(num%j==0) count++; if(count==3) break;} if(count==2) ans++;}printf("%d\n",ans);}return 0;}
0 0
- CF 26A-Almost prime
- 【详解打表】#26 A. Almost Prime
- Code Forces 26A Almost Prime
- codeforces-26A-Almost Prime【分解质因数】
- CodeForces 26 A.Almost Prime(数论)
- A. Almost Prime
- A. Almost Prime
- Codeforces Beta Round #26 (Codeforces format) A Almost Prime
- UVa10539 Almost Prime Numbers
- UVa10539 - Almost Prime Numbers
- UVA10539 - Almost Prime Numbers
- 10539 - Almost Prime Numbers
- 【codeforces26A】Almost Prime
- uva10539 Almost Prime Numbers
- Almost Prime Numbers UVA
- UVA 10539 Almost Prime
- Almost Prime Numbers UVA
- UVa 10539 - Almost Prime Numbers
- Dreamweaver工具使用
- hdoj1312Red and Black(递归)
- ubuntu下忘记root 密码的解决方法
- java事务相关异常的排查方法
- 如何用ThinkPHP的Save方法,保存未被修改的数值
- CF 26A-Almost prime
- QHeaderView的visualIndex和logicalIndex
- 25.UITouch
- POJ 1062 昂贵的聘礼
- RHEL6.4在RHCS环境下,重新划分LVM时遇到无法创建LV的问题
- LeetCode 之 Pow(x, n)(分治法)
- 关于学习编程的一些思考
- 8.4居中
- 批量删除项目中的.svn文件夹方法