题目传送门

Semi-prime H-numbers

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10871   Accepted: 4881

Description

This problem is based on an exercise of David Hilbert, who pedagogically suggested that one study the theory of 4n+1 numbers. Here, we do only a bit of that.

An H-number is a positive number which is one more than a multiple of four: 1, 5, 9, 13, 17, 21,... are the H-numbers. For this problem we pretend that these are the only numbers. The H-numbers are closed under multiplication.

As with regular integers, we partition the H-numbers into units, H-primes, and H-composites. 1 is the only unit. An H-number h is H-prime if it is not the unit, and is the product of two H-numbers in only one way: 1 × h. The rest of the numbers are H-composite.

For examples, the first few H-composites are: 5 × 5 = 25, 5 × 9 = 45, 5 × 13 = 65, 9 × 9 = 81, 5 × 17 = 85.

Your task is to count the number of H-semi-primes. An H-semi-prime is an H-number which is the product of exactly two H-primes. The two H-primes may be equal or different. In the example above, all five numbers are H-semi-primes. 125 = 5 × 5 × 5 is not an H-semi-prime, because it's the product of three H-primes.

Input

Each line of input contains an H-number ≤ 1,000,001. The last line of input contains 0 and this line should not be processed.

Output

For each inputted H-number h, print a line stating h and the number of H-semi-primes between 1 and h inclusive, separated by one space in the format shown in the sample.

Sample Input

21
85
789
0

Sample Output

21 0
85 5
789 62

Source


  分析:

  一道素数筛法的变式题。

  把素数筛法改一下,预处理出所有答案,然后直接输出每个答案就行了。

  Code:

//It is made by HolseLee on 2nd Sep 2018
//POJ3292
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std; const int N=1e6+;
int n,ans[N],q[N],top;
bool no[N],yes[N]; int main()
{
ios::sync_with_stdio(false);
for(int i=; i<N; i+=) {
if(no[i])continue;
q[++top]=i;
for(int j=*i; j<N; j+=i*) no[j]=;
}
for(int i=; i<=top; ++i)
for(int j=; j<=i && q[i]*q[j]<N; ++j)
yes[q[i]*q[j]]=;
for(int i=; i<N; ++i)
ans[i]=ans[i-]+yes[i]; while() {
cin>>n; if(!n) break;
cout<<n<<" "<<ans[n]<<"\n";
}
return ;
}

POJ3292 Semi-prime H-numbers [数论,素数筛]的更多相关文章

  1. Codeforces 385C - Bear and Prime Numbers(素数筛+前缀和+hashing)

    385C - Bear and Prime Numbers 思路:记录数组中1-1e7中每个数出现的次数,然后用素数筛看哪些能被素数整除,并加到记录该素数的数组中,然后1-1e7求一遍前缀和. 代码: ...

  2. UVALive-3399-Sum of Consecutive Prime Numbers(素数筛,暴力)

    原题链接 写个素数筛暴力打表一波就AC了: #include <iostream> using namespace std; const int N = 10001; int i, j, ...

  3. LightOJ-1259 Goldbach`s Conjecture 数论 素数筛

    题目链接:https://cn.vjudge.net/problem/LightOJ-1259 题意 给一个整数n,问有多少对素数a和b,使得a+b=n 思路 素数筛 埃氏筛O(nloglogn),这 ...

  4. 题解报告:poj 2689 Prime Distance(区间素数筛)

    Description The branch of mathematics called number theory is about properties of numbers. One of th ...

  5. HDU 1016 Prime Ring Problem (素数筛+DFS)

    题目链接 题意 : 就是把n个数安排在环上,要求每两个相邻的数之和一定是素数,第一个数一定是1.输出所有可能的排列. 思路 : 先打个素数表.然后循环去搜..... #include <cstd ...

  6. Bi-shoe and Phi-shoe LightOJ - 1370(数论+素数筛)

    题目链接:https://vjudge.net/problem/LightOJ-1370 题意:给你N个欧拉函数值,找出每一个大于等于该欧拉函数值的数,并且要求相加和最小. 题解:因为素数i的欧拉函数 ...

  7. [POJ268] Prime Distance(素数筛)

    /* * 二次筛素数 * POJ268----Prime Distance(数论,素数筛) */ #include<cstdio> #include<vector> using ...

  8. codeforces 414A A. Mashmokh and Numbers(素数筛)

    题目链接: A. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input ...

  9. POJ2689:Prime Distance(大数区间素数筛)

    The branch of mathematics called number theory is about properties of numbers. One of the areas that ...

  10. POJ 3126 Prime Path (bfs+欧拉线性素数筛)

    Description The ministers of the cabinet were quite upset by the message from the Chief of Security ...

随机推荐

  1. ubuntu环境下添加中文输入法

    1.下载软件包 打开终端,输入命令 sudo apt-get install fcitx-table-wbpy 2.打开 system settings-> language support-& ...

  2. echart图跟随屏幕自适应变化

    var myChart = echarts.init(document.getElementById('main'),'macarons');// var option = { //...一些配置 / ...

  3. linux 下 mysql 主从配置

    话不多说,直接干. 准备条件:安装两个mysql数据库,随便哪个作主库,另一个从库. 1.在主库创建 复制用的账号 grant replication slave ,replication clien ...

  4. Web 开发者易犯的5大严重错误

    无论你是编程高手,还是技术爱好者,在进行Web开发过程中,总避免不了犯各种各样的错误. 犯了错误,可以改正.但如果犯了某些错误,则会带来重大损失.遗憾.令人惊讶的是,这些错误往往是最普通,最容易避免. ...

  5. IO流-LineNumberReader

    LineNumberReader继承自BufferedReader,比其多了两个方法,用于设置和获取当前行号, setLineNumber(); getLineNumber();

  6. 在C++11中实现监听者模式

    参考文章:https://coderwall.com/p/u4w9ra/implementing-signals-in-c-11 最近在完成C++大作业时,碰到了监听者模式的需求. 尽管C++下也可以 ...

  7. NYOJ 1063 生活的烦恼 (二叉树)

    题目链接 描述 生活的暑假刚集训开始,他要决心学好字典树,二叉树,线段树和各种树,但生活在OJ上刷题的时候就遇到了一个特别烦恼的问题.那当然就是他最喜欢的二二叉树咯!题目是这样的:给你一颗非空的二叉树 ...

  8. NB二人组(一)----堆排序

    堆排序前传--树与二叉树简介 特殊且常用的树--二叉树  两种特殊的二叉树 二叉树的存储方式 二叉树小结 堆排序 堆这个玩意....... 堆排序过程: 构造堆: 堆排序的算法程序(程序需配合着下图理 ...

  9. Ajax+innerHTML+Dgls=好的用户体验+高性能+高效率

    为了引入Dgls,我们从创建Dom节点说起. 用JS创建Dom节点 var div = document.createElement('div'); div.className = 'gdls'; v ...

  10. php常用代码段

    点击换验证码 <a href=" src="{:U('Reglog/vcode')}" /></a> TP上一条下一条 $prev=$artica ...