类似素数筛。。。
Semi-prime H-numbers
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6873 Accepted: 2931

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

Waterloo Local Contest, 2006.9.30

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int MAXN=1000100;

int H[MAXN],cnt[MAXN];

void Init()
{
    for(int i=1;i<MAXN;i+=4)
    {
        H=1;
        for(int j=5;j*j<=i;j+=4)
        {
            if(i%j==0)
            {
                H=j;
                break;
            }
        }
    }
    for(int i=5;i<MAXN;i+=4)
    {
        cnt=cnt[i-4];
        if(H!=1&&H[i/H]==1)
        {
            cnt++;
        }
    }
}

int main()
{
    Init();
    int n;
    while(scanf("%d",&n)!=EOF&&n)
    {
        printf("%d %d\n",n,cnt[n]);
    }
    return 0;
}

* This source code was highlighted by YcdoiT. ( style: Codeblocks )

POJ 3292 Semi-prime H-numbers的更多相关文章

  1. 【POJ 3292】 Semi-prime H-numbers

    [POJ 3292] Semi-prime H-numbers 打个表 题意是1 5 9 13...这样的4的n次方+1定义为H-numbers H-numbers中仅仅由1*自己这一种方式组成 即没 ...

  2. POJ 3292 Semi-prime H-numbers (素数筛法变形)

    题意:题目比较容易混淆,要搞清楚一点,这里面所有的定义都是在4×k+1(k>=0)这个封闭的集合而言的,不要跟我们常用的自然数集混淆. 题目要求我们计算 H-semi-primes, H-sem ...

  3. Day7 - I - Semi-prime H-numbers POJ - 3292

    This problem is based on an exercise of David Hilbert, who pedagogically suggested that one study th ...

  4. POJ 3126:Prime Path(素数+BFS)

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

  5. 【POJ】1811 Prime Test

    http://poj.org/problem?id=1811 题意:求n最小素因子.(n<=2^54) #include <cstdio> #include <cstring& ...

  6. POJ 3292

    Semi-prime H-numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7059   Accepted: 3 ...

  7. POJ 2560 Freckles Prime问题解决算法

    这个问题正在寻求最小生成树. 给定节点的坐标,那么我们需要根据各个点之间的这些坐标来计算距离. 除了这是标准的Prime算法的,能源利用Prime基本上,你可以使用Kruskal. 经典的算法必须填写 ...

  8. poj 3925 枚举+prime

    /* 因为15很小可以暴力枚举然后用最小生成树的prim来计算 */ #include<stdio.h> #include<string.h> #include<math ...

  9. 【POJ 2689】 Prime Distance

    [题目链接] http://poj.org/problem?id=2689 [算法] 我们知道,一个在区间[l,r]中的合数的最小质因子必然不超过sqrt(r) 那么,先暴力筛出1-50000中的质数 ...

随机推荐

  1. CentOS找回root密码

    如果忘记了root密码,可以进入单用户模式进行密码重置. 重启系统,在grub的启动菜单中按下e键,然后编辑kernel那一行,在最后的quiet后加上single. 按下Enter后,再按b开机进入 ...

  2. Visual Studio 创建WebServer

    1.文件-->新建-->项目 2.Web-->Visual Studio 2012-->ASP.NET 空Web应用程序 3.右键项目-->添加-->新建项 4.选 ...

  3. 【Phylab2.0】Alpha版本测试报告

    测试报告集 点击链接

  4. 零散的JavaScript公用方法

    function stopBubble(e) { if (e && e.stopPropagation) {//如果传入了事件对象,那么就是非IE浏览器 e.stopPropagati ...

  5. React Native 开发之 (05) flexbox布局

    一  flexbox布局 1 flex布局 flexbox是ReactNative 应用开发中必不可少的内容,也是最常用的内容. 传统的页面布局是基于盒子模型,依赖定位属性,流动属性和显示属性来解决. ...

  6. 问题导向VS目标导向:领导者要倾向哪种?

    人类进步的驱动: 问题驱动:目标驱动: 两者相互影响: 问题驱动是起点,并且在很多杂乱的问题中只有少数可以转化为目标,从而成为进步的动力:多数问题只是以干扰的形式出现. 问题驱动是被动的,并且常常干扰 ...

  7. uC/OS-II内核的服务文件

    /*************************************************************************************************** ...

  8. C#读写文本文件

    static public string Read(string path) { StreamReader sr = new StreamReader(path,Encoding.Default); ...

  9. 20145212 实验三《敏捷开发与XP实践》

    20145212 实验三<敏捷开发与XP实践> 实验内容 使用git上传代码 与20145223同学一组,使用git相互更改代码 同组实验报告链接:http://www.cnblogs.c ...

  10. Linux下Memcache 安装和使用

    Memcached是一种高性能的分布式内存对象缓存系统(memcached虽然称为“分布式”缓存服务器,但服务器端并没有“分布式”功能,其“分布式”由客户端函数库完成,成熟算法的为一致性Hash),用 ...