Description
Almost Prime
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
 
 
 
 
 
 
题解:
  素因子数的种类有且只有两种,称为Almost Prime。
       例如:18=2*3*3,只有2和3,是Almost Prime。
       求1~n Almost Prime 数量。
代码:
 #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;
}

Problem -26A - Codeforces

转载请注明出处:http://www.cnblogs.com/michaelwong/p/4133164.html

 

Almost Prime的更多相关文章

  1. Java 素数 prime numbers-LeetCode 204

    Description: Count the number of prime numbers less than a non-negative number, n click to show more ...

  2. Prime Generator

    Peter wants to generate some prime numbers for his cryptosystem. Help him! Your task is to generate ...

  3. POJ 2739. Sum of Consecutive Prime Numbers

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050 ...

  4. UVa 524 Prime Ring Problem(回溯法)

    传送门 Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbe ...

  5. Sicily 1444: Prime Path(BFS)

    题意为给出两个四位素数A.B,每次只能对A的某一位数字进行修改,使它成为另一个四位的素数,问最少经过多少操作,能使A变到B.可以直接进行BFS搜索 #include<bits/stdc++.h& ...

  6. hdu 5901 count prime & code vs 3223 素数密度

    hdu5901题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5901 code vs 3223题目链接:http://codevs.cn/problem ...

  7. 最小生成树 prime zoj1586

    题意:在n个星球,每2个星球之间的联通需要依靠一个网络适配器,每个星球喜欢的网络适配器的价钱不同,先给你一个n,然后n个数,代表第i个星球喜爱的网络适配器的价钱,然后给出一个矩阵M[i][j]代表第i ...

  8. 最小生成树 prime poj1258

    题意:给你一个矩阵M[i][j]表示i到j的距离 求最小生成树 思路:裸最小生成树 prime就可以了 最小生成树专题 AC代码: #include "iostream" #inc ...

  9. 最小生成树 prime + 队列优化

    存图方式 最小生成树prime+队列优化 优化后时间复杂度是O(m*lgm) m为边数 优化后简直神速,应该说对于绝大多数的题目来说都够用了 具体有多快呢 请参照这篇博客:堆排序 Heapsort / ...

  10. 最小生成树 prime poj1287

    poj1287 裸最小生成树 代码 #include "map" #include "queue" #include "math.h" #i ...

随机推荐

  1. 多线程程序中fork导致的一些问题

    最近项目中,在使用多线程和多进程时,遇到了些问题. 问题描述:在多线程程序中fork出一个新进程,发现新的进程无法正常工作. 解决办法:将开线程的代码放在fork以后.也就是放在新的子进程中进行创建. ...

  2. linux 查看目录名称的方法

    1. ls -d * 2. grep查找以'/'结尾的,也就是目录 ls -F | grep '/$'

  3. 复习:IPC机制

    一.为什么需要IPC机制 当我们开启多个进程的时候,我们有时需要和各个进程进行交互.但是进程间的交互就不能够共享对象(就是进程A中创建了一个对象,进程B中的类或者方法不能够直接使用,需要用到IPC机制 ...

  4. thinkphp框架开启页面gzip压缩

    Thinkphp下开启gzip压缩很简单,不管你是哪个版本,只要在你的入口文件index.PHP中加入以下两行,如果你的服务器支持,那么就OK了. define ( "GZIP_ENABLE ...

  5. jQuery插件jqplot的详细配置说明和渲染器

    jQuery插件jqplot的详细配置说明和渲染器 (2012-08-23 08:57:42) 转载▼ 标签: jqplot 详细配置 渲染器 it 分类: 技术类 jQuery.jqplot插件的官 ...

  6. DEP受保护的问题(尤其是Outlook)

    We see this issue quite regularly as we use MAPI and lots of our users run our application on TS. Of ...

  7. CDOJ 631 敢说敢做 记忆化搜索and动规

    //跟沈爷学的 传送门http://www.cnblogs.com/Xiper/p/4639636.html #include<cstdio> #include<iostream&g ...

  8. 使用httpwatch抓包

    httpwatch抓包工具是MS的ie自带的一个插件. 但是千里之行始于足下,所以先来利用httpwatch抓一些包来分析分析. 打开IE,快捷键shift+F2打开httpwatch. 如下图: 本 ...

  9. hdu 1599 find the mincost route_最小环

    #include <iostream> #include<cstdio> using namespace std; #define N 110 #define INF 0xff ...

  10. lhgDialog

    应用到你的项目 如果您使用独立版本的lhgDialog窗口组件,您只需在页面head中引入lhgcore.lhgdialog.min.js文件,4.1.1+版本做了修改可以和jQuerya库同时引用, ...