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

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

 
 
仿照素数的埃氏筛选法即可
 
 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std; #define maxn 1000005 bool H[maxn];
int ans[maxn],ele[maxn];
int len = ; void init() { for(int i = ; i <= maxn - ; i++) {
H[i] = (i % == );
} for(int i = ; i * i <= maxn - ; i += ) {
if(!H[i]) continue;
for(int j = i; j * i <= maxn - ; j++) {
H[j * i] = ;
}
} for(int i = ; i <= maxn - ; i += ) {
if(H[i]) {
ele[len++] = i;
}
} for(int i = ; i < len && ele[i] * ele[i] <= maxn - ; i++) {
for(int j = i; j < len && ele[j] * ele[i] <= maxn - ; j++) {
if(ele[i] * ele[j] % == )
ans[ ele[i] * ele[j] ] = ;
}
} for(int i = ; i <= maxn - ; i++) {
ans[i] += ans[i - ];
}
} int main() {
// freopen("sw.in","r",stdin); init(); int x;
while(~scanf("%d",&x) && x) {
printf("%d %d\n",x,ans[x]);
} return ; }

POJ 3292的更多相关文章

  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

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

  3. Mathematics:Semi-prime H-numbers(POJ 3292)

      Semi-prime H-numbers 题目大意,令4n+1的数叫H数,H数素数x的定义是只能被x=1*h(h是H数),其他都叫合数,特别的,当一个数只能被两个H素数乘积得到时,叫H-semi数 ...

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

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

  5. Semi-prime H-numbers POJ - 3292 打表(算复杂度)

    题意:参考https://blog.csdn.net/lyy289065406/article/details/6648537 一个H-number是所有的模四余一的数. 如果一个H-number是H ...

  6. poj 3292 H-素数问题 扩展艾氏筛选法

    题意:形似4n+1的被称作H-素数,两个H-素数相乘得到H-合成数.求h范围内的H-合成数个数 思路: h-素数                                            ...

  7. 筛选法 || POJ 3292 Semi-prime H-numbers

    5,9,13,……叫H-prime 一个数能且仅能由两个H-prime相乘得到,则为H-semi-prime 问1-n中的H-semi-prime有多少个 *解法:vis初始化为0代表H-prime, ...

  8. POJ 3292:Semi-prime H-numbers 筛选数

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

  9. 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 ...

随机推荐

  1. 洛谷 P3399 丝绸之路

    题目背景 张骞于公元前138年曾历尽艰险出使过西域.加强了汉朝与西域各国的友好往来.从那以后,一队队骆驼商队在这漫长的商贸大道上行进,他们越过崇山峻岭,将中国的先进技术带向中亚.西亚和欧洲,将那里的香 ...

  2. 死亡之ping(Ping of Death)

    最简单的基于IP的攻击可能要数著名的死亡之ping,这种攻击主要是由于单个包的长度超过了IP协议规范所规定的包长度.产生这样的包很容易,事实上,许多操作系统都提供了称为ping的网络工具.在为Wind ...

  3. 利用Nutch和Tomcat构建搜索引擎

    利用Nutch和Tomcat构建搜索引擎 1.安装环境及软件版本介绍 本教程是在Linux Ubuntu 12.04 desktop i386操作系统上搭建,结合使用了Nutch-1.2和Apache ...

  4. Windows Phone 8.1开发:如何从ListView中,获取ScrollViewer对象

    在使用ListView作为信心呈现载体开发应用程序时,我们经常需要通过监视滚动条(ScrollViewer)的位置状态来完成一些交互逻辑.最直接的体现就是 延时加载,(上滑加载更多,下拉获取更新数据) ...

  5. 学习CentOS7笔记(一)

    说明: 1.这是我第一次接触CentOS7,从基础学起. 2.最终目的是为了在CentOS上面部ngix+php+mysql+naxsi环境,进行安全测试. 第一部分 认识CentOS 7 有时候我在 ...

  6. Java包的命名规则

    按照惯例,包申明遵循特定的格式.虽然不是严格要求的Java语法,如果不遵循格式要求,大多数的Java认为你是不懂Java. 从右到左的顺序是: 1.systaxExample表明包的本地名称. 2.e ...

  7. DataGridView导入导出excel

    DataGridView导出到Excel #region 方法一 DateGridView导出到csv格式的Excel /// <summary> /// 导出数据到Excel.常用方法, ...

  8. [Android教程]TextView使用SpannableString设置复合文本

    TextView通常用来显示普通文本,但是有时候需要对其中某些文本进行样式.事件方面的设置.Android系统通过SpannableString类来对指定文本进行相关处理,具体有以下功能: 1.Bac ...

  9. nodejs ssh2

    https://www.npmjs.com/package/ssh2 npm install ssh2  ssh2文件下载: //前台命令下发 app.get('/test/fileDownload' ...

  10. Android 中的WiFi剖析

    Android的WiFi 我们通常看到WiFi的守护进程wpa_supplicant在我们的ps的进程列表中,这个就是我们的wifi守护进程.wpa_supplicant在external/wpa_s ...