Semi-prime H-numbers
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 8706   Accepted: 3809

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
思路:注意H数的域是模4余1的数。如9是H数,虽然在自然数范围内9不是素数但是在H数域内9是H-prime。
#include <iostream>
#include <string.h>
using namespace std;
const int MAXN=;
bool isHprime[MAXN];
int Hprime[MAXN],top;
int h[MAXN];
void sieve()
{
memset(isHprime,true,sizeof(isHprime));
for(int i=;i<MAXN;i+=)
{
if(isHprime[i])
{
Hprime[top++]=i;
for(int j=i+i;j<MAXN;j+=i)
{
if((j-)%==)
{
isHprime[j]=false;
}
}
}
}
for(int i=;i<top;i++)
{
if(Hprime[i]>) break;
for(int j=i;j<top;j++)
{
int mul=Hprime[i]*Hprime[j];
if(mul>=MAXN)
{
break;
}
h[mul]=;
}
}
for(int i=;i<MAXN;i++)
{
h[i]+=h[i-];
}
}
int main()
{
sieve();
int n;
while(cin>>n&&n!=)
{
cout<<n<<" "<<h[n]<<endl;
}
return ;
}

POJ3292(素数筛选)的更多相关文章

  1. 1341 - Aladdin and the Flying Carpet ---light oj (唯一分解定理+素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1341 题目大意: 给你矩形的面积(矩形的边长都是正整数),让你求最小的边大于等于b的矩形的个数. ...

  2. codeforces Soldier and Number Game(dp+素数筛选)

    D. Soldier and Number Game time limit per test3 seconds memory limit per test256 megabytes inputstan ...

  3. POJ 3978 Primes(素数筛选法)

    题目 简单的计算A,B之间有多少个素数 只是测试数据有是负的 //AC //A和B之间有多少个素数 //数据可能有负的!!! #include<string.h> #include< ...

  4. POJ 2689 Prime Distance (素数筛选法,大区间筛选)

    题意:给出一个区间[L,U],找出区间里相邻的距离最近的两个素数和距离最远的两个素数. 用素数筛选法.所有小于U的数,如果是合数,必定是某个因子(2到sqrt(U)间的素数)的倍数.由于sqrt(U) ...

  5. algorithm@ Sieve of Eratosthenes (素数筛选算法) & Related Problem (Return two prime numbers )

    Sieve of Eratosthenes (素数筛选算法) Given a number n, print all primes smaller than or equal to n. It is ...

  6. LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1236 Pairs Forming LCM Time Limit:2000MS     Memor ...

  7. LightOJ 1259 Goldbach`s Conjecture (哥德巴赫猜想 + 素数筛选法)

    http://lightoj.com/volume_showproblem.php?problem=1259 题目大意:给你一个数n,这个数能分成两个素数a.b,n = a + b且a<=b,问 ...

  8. LightOJ 1341 - Aladdin and the Flying Carpet (唯一分解定理 + 素数筛选)

    http://lightoj.com/volume_showproblem.php?problem=1341 Aladdin and the Flying Carpet Time Limit:3000 ...

  9. poj 2262 Goldbach's Conjecture(素数筛选法)

    http://poj.org/problem?id=2262 Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total ...

随机推荐

  1. MATLAB更换字体后 中文显示乱码问题

    MATLAB的脚本代码默认宋体显示,对于大多数720P的显示器来说,无论是中文还是英文,显示效果都非常差.Windows环境下,Consolas是一种比较理想的英文代码字体. Consolas 字体是 ...

  2. CCNA 课程 一

    OSI 参考模型: 7应用层 6表示层 5会话层 4传输层   --  TCP / UDP (端口号) 3网络层   --  IP (原IP地址,目标IP地址) 2数据链路层  -- ARPA / e ...

  3. Response对象介绍(服务器到客户端)

    1.response的状态码和响应头设置 package com.test; import java.io.IOException; import java.io.PrintWriter; impor ...

  4. 关于谷歌浏览器(chrome)的一些好用的插件推荐

    很多在测试时候都可以使用 第一部分: A:Adblock Plus for Google Chrome™https://chrome.google.com/webstore/detail/cfhdoj ...

  5. (转) 一次批量重启引发的Neutron网络故障

    现场回顾 故事发生于某个下午,采用 salt 更新某集群的 neutron.conf (log 相关配置项) 并批量重启 neutron-openvswitch-agent(以下简称 neutron- ...

  6. dp4--codeVs1043 方格取数

    dp4--codeVs1043 方格取数 一.心得 二.题目 1043 方格取数 2000年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Dia ...

  7. jar包作用

    hibernate中jar包的作用 (1)hibernate3.jar:Hibernate的核心库,没有什么可说的,必须使用的jar包 (2)cglib-asm.jar:CGLIB库,Hibernat ...

  8. IDEA配置JavaWeb项目Artifacts

  9. SQL Server循环插入数据

    --循环执行插入10000条数据declare @ID intdeclare @eigyousyocode nvarchar(16)declare @datet datetimedeclare @pl ...

  10. EXCEL对比重复数据

    一.       EXCEL 突出重复项 1.      选择对应的数据 EXCEL 里选择好数据 2.      选择条件格式 这样就完成了数据重复的突出,可以按条件筛选.选择自己想要的数据