类似素数筛。。。
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. shutil模块

    shutil模块 提供了大量的文件的高级操作,特别针对文件拷贝和删除,主要功能为目录和文件操作以及压缩操作 常用方法 shutil.copyfile(src, dst) 复制文件内容(不包含元数据)从 ...

  2. Simultaneous Tag Editing in IntelliJ IDEA 14.1

    If you're involved in web development and, for some reason, you haven't given a ride to IntelliJ IDE ...

  3. Linux Basis --- commands of vi

    EDIT mode to GENERAL mode: press ESC general mode: CLOSE FILE :q!    :force to close the file but no ...

  4. JAVASE 面试总结(1)

    1.什么是Java虚拟机?为什么Java被称作是"平台无关的编程语言"?Java虚拟机是一个可以执行Java字节码的虚拟机进程.Java源文件被编译成能被Java虚拟机执行的字节码 ...

  5. 一种M2M业务的架构及实现M2M业务的方法

    http://www.cnblogs.com/coryxie/p/3849764.html 技术领域 [0001] 本发明涉及通信技术领域,尤其涉及一种M2M业务的架构及实现M2M业务的方法. 背景技 ...

  6. ORACLE 错误:oralce record is locked by another user

     方法/步骤     打开PL/SQL客户端,然后修改表记录中的数据,提交修改,如下提示 步骤阅读 2 我们关闭异常警告窗口,在执行sql的窗口中输入如下命令:select t2.username,t ...

  7. shell操作mysql之增删改查

    假设mysql用户名root 密码123456,新建测试数据表utable 脚本如下: #!/bin/bash#mysqlop.shmysql="/app/local/mysql/bin/m ...

  8. 使用.net Stopwatch class 来分析你的代码

    当我们在调试,优化我们的代码的时候,想知道某段代码的真正的执行时间,或者我们怀疑某段代码,或是某几段代码执行比较慢, 需要得到具体的某段代码的具体执行时间的时候.有一个很好用的类Stopwatch. ...

  9. UI控件之ListView

    一,一个简单的TextView列表 public class FirstActivity extends Activity { private String[] data = {"Apple ...

  10. Robot Framework--11 RF结合Jenkins

    转自:http://blog.csdn.net/tulituqi/article/details/17846463 为什么我们要引入RF?其实最初我们引入RF是为了能够快速的开展自动化验收测试,为敏捷 ...