A. Almost Prime

来源:互联网 发布:激活淘宝怎么实名认证 编辑:程序博客网 时间:2024/06/03 06:45

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Input contains one integer number n (1 ≤ n ≤ 3000).

Output

Output the amount of almost prime numbers between 1 and n, inclusive.

Sample test(s)
input
10
output
2
input
21
output
8


解题说明:题目中要求是找出只含有两个因子的数字,首先求出该数有哪些因子,再判断这些因子是否包含更小的因子,可以用数组来存放每个数对应的因子总数,循环判断即可。


#include<iostream>#include<map>#include<string>#include<algorithm>#include<cstdio>#include<cmath>using namespace std;int a[5000];int main () {int n,res=0;int i,j;scanf("%d",&n);for (i=2;i<=n;i++) {for (j=2;j<i;j++){if (a[j]==0 && i%j==0){a[i]++;}}if (a[i]==2) {res++;}}printf("%d\n",res);return 0;}