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. linux下C++ STL hash_map的使用以及使用char *型变量作为Key值的一大“坑”

    计算机编程中经常会用到hash表,而在C++中,使用STL编程更是少不了的.本文将介绍STL中hash_map的使用.在hash_map中使用自定义类型作为key值的方法以及在使用char *类型作为 ...

  2. eclipse +cvs 的基本使用方法(一)

    很多时候我们在做项目开发时,会用到cvs,现在我给大家介绍一下关于eclipse下怎么使用cvs管理功能,eclipse本身是自带cvs的,我们只要简单设置一下让它连接到cvs服务器上.    看下图 ...

  3. wordpress一些常用代码

    显示最新文章 <div id="newpost"> <h2> 最新文章</h2> <?php $previous_posts = get_ ...

  4. 自定义filter

    class md5_filter extends php_user_filter{ public function filter($in,$out,&$consumed,$closing){ ...

  5. oracle全文检索笔记

    1.删除词法解析器 exec ctx_ddl.drop_preference('my_lexer'); 2.创建中文词法解析器 exec ctx_ddl.create_preference ('my_ ...

  6. 匈牙利算法(素数伴侣(HW1112))

    #define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<vector> #include<string&g ...

  7. Hibernate 体系结构简述

    SessionFactory: Hibernate的关键对象,它是单个数据库映射关系经过编译后的内存镜像,同时它是线程安全的.它是生成Session的工厂,本身需要依赖于ConnectionProvi ...

  8. javascript 事件设计模式

    http://plkong.iteye.com/blog/213543 1. 事件设计概述 事件机制可以是程序逻辑更加清晰可见,在JavaScript中很多对象都有自己的事件,如:button有onc ...

  9. KeybMap 键盘映射工具更新至 V1.5(修订)

    KeybMap 更新至 V1.5,主要是增加了对一些多媒体键定义修改功能,也可以将任意一键定义为打开指定的程序. 3月9日略做修订. http://www.mympc.org/down/1/2005- ...

  10. Inno Setup 系统托盘图标插件 TrayIconCtrl V1.5

    原文 http://restools.hanzify.org/article.asp?id=93 V1.5 修正在某些 Windows 平台上(例如 Windows XP SP3)不能正常运行的问题. ...