POJ 3292 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() int main() |
* This source code was highlighted by YcdoiT. ( style: Codeblocks )
POJ 3292 Semi-prime H-numbers的更多相关文章
- 【POJ 3292】 Semi-prime H-numbers
[POJ 3292] Semi-prime H-numbers 打个表 题意是1 5 9 13...这样的4的n次方+1定义为H-numbers H-numbers中仅仅由1*自己这一种方式组成 即没 ...
- POJ 3292 Semi-prime H-numbers (素数筛法变形)
题意:题目比较容易混淆,要搞清楚一点,这里面所有的定义都是在4×k+1(k>=0)这个封闭的集合而言的,不要跟我们常用的自然数集混淆. 题目要求我们计算 H-semi-primes, H-sem ...
- 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 ...
- POJ 3126:Prime Path(素数+BFS)
The ministers of the cabinet were quite upset by the message from the Chief of Security stating that ...
- 【POJ】1811 Prime Test
http://poj.org/problem?id=1811 题意:求n最小素因子.(n<=2^54) #include <cstdio> #include <cstring& ...
- POJ 3292
Semi-prime H-numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7059 Accepted: 3 ...
- POJ 2560 Freckles Prime问题解决算法
这个问题正在寻求最小生成树. 给定节点的坐标,那么我们需要根据各个点之间的这些坐标来计算距离. 除了这是标准的Prime算法的,能源利用Prime基本上,你可以使用Kruskal. 经典的算法必须填写 ...
- poj 3925 枚举+prime
/* 因为15很小可以暴力枚举然后用最小生成树的prim来计算 */ #include<stdio.h> #include<string.h> #include<math ...
- 【POJ 2689】 Prime Distance
[题目链接] http://poj.org/problem?id=2689 [算法] 我们知道,一个在区间[l,r]中的合数的最小质因子必然不超过sqrt(r) 那么,先暴力筛出1-50000中的质数 ...
随机推荐
- 心血来潮学python
第一次见python就被吸引了,嗯,前面在linux下调试过一些小段代码.最近工作都在windows下面,也懒得换去unbuntu,所以想着在win下安装python. 之前不知道用什么方法装的pyt ...
- iOS应用第三方推送的添加
现在的一些第三方的推送平台挺好用,主要是因为他们有类似微信公众平台一样的管理后台,简单易用,封装了很多开发者需要的推送功能. 下面以个推为例: 1.在个推的应用配置iOS部分设置自己的BounleID ...
- Entity Framework使用Sqlite时的一些配置
前段时间试着用Entity Framework for Sqlite环境,发现了一些坑坑洼洼,记录一下. 同时试了一下配置多种数据库,包括Sqlite.Sql Server.Sql Server Lo ...
- Error: cannot find a valid baseurl for repo: rpmfusion-free 解决办法
今天在玩CentOS的时候出现了: Error: cannot find a valid baseurl for repo: rpmfusion-free 这个问题真到好恶心啊,以前一直使用到是ubu ...
- CF 701C They Are Everywhere(尺取法)
题目链接: 传送门 They Are Everywhere time limit per test:2 second memory limit per test:256 megabytes D ...
- iOS - 装饰对象
1.设计模式原则 多组合,少继承 类对拓展开放,对修改关闭 派生的子类接口是在编译时就静态决定的,而所有子类都会继承到相同的接口.然而,利用组合或者说装饰模式来拓展抽象类的接口,就可以在运行时动态的进 ...
- POJ 1038 Bugs Integrated, Inc.
AC通道 神坑的一道题,写了三遍. 两点半开始写的, 第一遍是直接维护两行的二进制.理论上是没问题的,看POJ discuss 上也有人实现了,但是我敲完后准备开始调了.然后就莫名其妙的以为会超时,就 ...
- jquery 解析数据库中的json日期为正常的格式
//在action从后台数据库中请求获得日期以后,得到的是json格式的数据,因此要解析才能显示在前台1.在jsp页面写的代码如下:<html> <script> Date.p ...
- 第四章 电商云化,4.1 17.5W秒级交易峰值下的混合云弹性架构之路(作者:唐三 乐竹 锐晟 潇谦)
4.1 17.5W秒级交易峰值下的混合云弹性架构之路 前言 每年的双11都是一个全球狂欢的节日,随着每年交易逐年创造奇迹的背后,按照传统的方式,我们的成本也在逐年上升.双11当天的秒级交易峰值平时的近 ...
- Zookeeper集群的安装和使用
Apache Zookeeper 由 Apache Hadoop 的 Zookeeper 子项目发展而来,现已经成为 Apache 的顶级项目,它是一个开放源码的分布式应用程序协调服务,是Google ...