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

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

  1. 21
  2. 85
  3. 789
  4. 0

Sample Output

  1. 21 0
  2. 85 5
  3. 789 62

Source

大致题意:

一个H-number是所有的模四余一的数。

如果一个H-number是H-primes 当且仅当它的因数只有1和它本身(除1外)。

一个H-number是H-semi-prime当且仅当它只由两个H-primes的乘积表示。

H-number剩下其他的数均为H-composite。

给你一个数h,问1到h有多少个H-semi-prime数。

解题思路:

感觉跟同余模扯不上关系。。。

筛法打表,再直接输出。。。水题。。。

ps:请用G++提交

  1. #include<iostream>
  2. using namespace std;
  3. const int N=;
  4. int h,a[N+];
  5. int go(){
  6. for(int i=;i<=N;i+=){
  7. for(int j=;j<=N;j+=){
  8. int tmp=i*j;
  9. if(tmp>N) break;
  10. if(!a[i]&&!a[j])//i与j均为H-prime
  11. a[tmp]=; //tmp为H-semi-primes
  12. else
  13. a[tmp]=-;//tmp为H-composite
  14. }
  15. }
  16. int p=; //H-prime计数器
  17. for(int i=;i<=N;i++){
  18. if(a[i]==) p++;
  19. a[i]=p; //从1到i有p个H-semi-primes
  20. }
  21. }
  22. int main(){
  23. go();
  24. while(cin>>h){
  25. if(!h) break;
  26. cout<<h<<' '<<a[h]<<endl;
  27. }
  28. return ;
  29. }

poj3292的更多相关文章

  1. POJ-3292 Semi-prime H-numbers---筛素数

    题目链接: https://vjudge.net/problem/POJ-3292 题目大意: 定义一种数叫H-numbers,它是所有能除以四余一的数. 在H-numbers中分三种数: 1.H-p ...

  2. poj3292(筛法+打表)

    题目链接:https://vjudge.net/problem/POJ-3292 题意:定义4n+1数(简称H数),H数分为三类:unit,即为1; H-primes,只能分解为1×自身,类似于我们平 ...

  3. POJ3292 Semi-prime H-numbers [数论,素数筛]

    题目传送门 Semi-prime H-numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10871   Acce ...

  4. POJ3292 Semi-prime H-numbers

    传送门: 刷<数论一本通>时看到的题,简单记录一下. 题目大意(照抄书上的):形如4n+1的数被称为H数,乘法在H数组成的集合内是封闭的.在这个集合中是能被1和本身整除的数叫H-素数,其余 ...

  5. POJ3292&&2115

    这两道题还是比较简单的,没有什么难度 不过归在数论这个专题里我还是比较认同的,多少有些关系 3292 题目大意:给你一个范围n,让你求出这个范围内所有形式类似\(4k+1(k为正整数)\)的数中的H- ...

  6. POJ3292(素数筛选)

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

  7. poj分类 很好很有层次感。

    初期: 一.基本算法:      (1)枚举. (poj1753,poj2965)      (2)贪心(poj1328,poj2109,poj2586)      (3)递归和分治法.      ( ...

  8. 【转】POJ题目分类推荐 (很好很有层次感)

    OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...

  9. 【转】ACM训练计划

    [转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...

随机推荐

  1. mysql行转列,单列转多行

    行转列 使用CASE语句: SELECT SUM(CASE USER_NAME='A' THEN KILLS END) AS 'A', SUM(CASE USERNAME='B' THEN KILL ...

  2. appium python api(转)

    Appium_Python_Api文档 1.contextscontexts(self): Returns the contexts within the current session. 返回当前会 ...

  3. jquery给多个span赋值

    因为我想在页面载入完毕后,有几个地方显示当前时间,所以我须要给多个span赋值. span代码的写法例如以下: <span name="currentDate">< ...

  4. WEB接口测试之Jmeter接口测试自动化 (三)(数据驱动测试) 接口测试与数据驱动

    转载:http://www.cnblogs.com/chengtch/p/6576117.html 1简介 数据驱动测试,即是分离测试逻辑与测试数据,通过如excel表格的形式来保存测试数据,用测试脚 ...

  5. web-压力测试学习

    https://blog.linuxeye.com/335.html http://bdql.iteye.com/blog/291987 http://www.cnblogs.com/zhuque/a ...

  6. 代码设置UIButton文字、图片位置

    假设有按钮rButton的 imageEdgeInsets和contentEdgeInsets可以设置按钮的标题和图片的位置,如下代码,设置标题居右 NSString * rBtnTitle = @& ...

  7. excel表格快捷键

    CTRL+A   全选     CTRL+B   加粗       CTRL+C   复制      CTRL+D   下拉(复制上一个单元格的格式和内容)    CTRL+G   定位 CTRL+F ...

  8. Android文章收藏

     Android集 1.Himi李华明的<Android游戏开发专栏>http://blog.csdn.net/column/details/androidgame.html2.老罗的&l ...

  9. Mac下面的SecureCRT(附破解方案) 更新到最新的7.3.2(转)

    转自 http://bbs.weiphone.com/read-htm-tid-6939481.html 继续更新到7.3.2的破解.只是升级了下secureCRT到7.3.2,方法还是不变 相信很多 ...

  10. 第九章 用多线程来读取epoll模型下的client数据

    #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include &l ...