poj3292
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
- 21
- 85
- 789
- 0
Sample Output
- 21 0
- 85 5
- 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++提交
- #include<iostream>
- using namespace std;
- const int N=;
- int h,a[N+];
- int go(){
- for(int i=;i<=N;i+=){
- for(int j=;j<=N;j+=){
- int tmp=i*j;
- if(tmp>N) break;
- if(!a[i]&&!a[j])//i与j均为H-prime
- a[tmp]=; //tmp为H-semi-primes
- else
- a[tmp]=-;//tmp为H-composite
- }
- }
- int p=; //H-prime计数器
- for(int i=;i<=N;i++){
- if(a[i]==) p++;
- a[i]=p; //从1到i有p个H-semi-primes
- }
- }
- int main(){
- go();
- while(cin>>h){
- if(!h) break;
- cout<<h<<' '<<a[h]<<endl;
- }
- return ;
- }
poj3292的更多相关文章
- POJ-3292 Semi-prime H-numbers---筛素数
题目链接: https://vjudge.net/problem/POJ-3292 题目大意: 定义一种数叫H-numbers,它是所有能除以四余一的数. 在H-numbers中分三种数: 1.H-p ...
- poj3292(筛法+打表)
题目链接:https://vjudge.net/problem/POJ-3292 题意:定义4n+1数(简称H数),H数分为三类:unit,即为1; H-primes,只能分解为1×自身,类似于我们平 ...
- POJ3292 Semi-prime H-numbers [数论,素数筛]
题目传送门 Semi-prime H-numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10871 Acce ...
- POJ3292 Semi-prime H-numbers
传送门: 刷<数论一本通>时看到的题,简单记录一下. 题目大意(照抄书上的):形如4n+1的数被称为H数,乘法在H数组成的集合内是封闭的.在这个集合中是能被1和本身整除的数叫H-素数,其余 ...
- POJ3292&&2115
这两道题还是比较简单的,没有什么难度 不过归在数论这个专题里我还是比较认同的,多少有些关系 3292 题目大意:给你一个范围n,让你求出这个范围内所有形式类似\(4k+1(k为正整数)\)的数中的H- ...
- POJ3292(素数筛选)
Semi-prime H-numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8706 Accepted: 3 ...
- poj分类 很好很有层次感。
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- 【转】POJ题目分类推荐 (很好很有层次感)
OJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094)初期: 一. ...
- 【转】ACM训练计划
[转] POJ推荐50题以及ACM训练方案 -- : 转载自 wade_wang 最终编辑 000lzl POJ 推荐50题 第一类 动态规划(至少6题, 和 必做) 和 (可贪心) (稍难) 第二类 ...
随机推荐
- Json,String,Map之间的转换
前提是String的格式是map或json类型的 String 转Json JSONObject jasonObject = JSONObject.fromObject(str); String 转 ...
- Android学习(二十一)OptionsMenu选项菜单
一.OptionsMenu选项菜单 在应用程序中点击功能按钮会弹出选项菜单,点击可以实现具体功能. 二.实现思路: 1.创建选项菜单: onCreateOptionsMenu(); 2.设置菜单项可用 ...
- Linux组件封装(一)中互斥锁MutexLock的封装
本文对Linux中的pthread_mutex_t做一个简易的封装. 互斥锁主要用于互斥,互斥是一种竞争关系,主要是某一个系统资源或一段代码,一次做多被一个线程访问. 条件变量主要用于同步,用于协调线 ...
- Hbase笔记1-2
吴超1.1 Hbase是Hadoop中的数据库,Hadoop还需要数据库吗?我们学的Hadoop是一个分布式的存储和计算的平台为什么要在他上面建一个数据库呢,数据库是干什么的呢,数据库是一个管理系统( ...
- 北大BBS2008年毕业生晒工资
http://www.amznz.com/19/快消类: 宝洁:本7200.研8200.博9700,均14个月,另有800交通补助,marketing每9个月 涨20%-30%. 玛氏:月薪10000 ...
- Word基本文档字体设置
另:段落行距选择:固定值:26/28
- asp.net core mvc视频A:笔记3-5.视图数据共享之TempData
前几节讲的都是单页面数据共享,从本节开始讲跨页面数据共享 创建项目3.5,新建控制器 代码 控制器 设置TempData 另一个视图中读取TempData数据 运行 此时如果刷新页面,页面中的内容“张 ...
- CDN对于动态加速是否有效
CDN对于动态加速是否有效的问题.关于这个问题,一直存在一些分歧,部分人认为有效,部分人认为无效,主要是CDN技术也在更新,而且是比较低调的进行着更新,所以并不是所有人都清楚CDN对动态加速的效果.其 ...
- Sql视图创建语句及修改视图
create view [dbo].[AllUsers] as select u.UserId, u.Firstname, u.Lastname, u.ts, am.Email, au.UserNam ...
- Spring事务管理之声明式事务管理:基于TransactionProxyFactoryBean的方式
© 版权声明:本文为博主原创文章,转载请注明出处 案例 - 利用Spring的声明式事务(TransactionProxyFactoryBean)管理模拟转账过程 数据库准备 -- 创建表 CREAT ...