POJ3292 Semi-prime H-numbers [数论,素数筛]
Semi-prime H-numbers
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 10871 | Accepted: 4881 |
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
分析:
一道素数筛法的变式题。
把素数筛法改一下,预处理出所有答案,然后直接输出每个答案就行了。
Code:
//It is made by HolseLee on 2nd Sep 2018
//POJ3292
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<algorithm>
using namespace std; const int N=1e6+;
int n,ans[N],q[N],top;
bool no[N],yes[N]; int main()
{
ios::sync_with_stdio(false);
for(int i=; i<N; i+=) {
if(no[i])continue;
q[++top]=i;
for(int j=*i; j<N; j+=i*) no[j]=;
}
for(int i=; i<=top; ++i)
for(int j=; j<=i && q[i]*q[j]<N; ++j)
yes[q[i]*q[j]]=;
for(int i=; i<N; ++i)
ans[i]=ans[i-]+yes[i]; while() {
cin>>n; if(!n) break;
cout<<n<<" "<<ans[n]<<"\n";
}
return ;
}
POJ3292 Semi-prime H-numbers [数论,素数筛]的更多相关文章
- Codeforces 385C - Bear and Prime Numbers(素数筛+前缀和+hashing)
385C - Bear and Prime Numbers 思路:记录数组中1-1e7中每个数出现的次数,然后用素数筛看哪些能被素数整除,并加到记录该素数的数组中,然后1-1e7求一遍前缀和. 代码: ...
- UVALive-3399-Sum of Consecutive Prime Numbers(素数筛,暴力)
原题链接 写个素数筛暴力打表一波就AC了: #include <iostream> using namespace std; const int N = 10001; int i, j, ...
- LightOJ-1259 Goldbach`s Conjecture 数论 素数筛
题目链接:https://cn.vjudge.net/problem/LightOJ-1259 题意 给一个整数n,问有多少对素数a和b,使得a+b=n 思路 素数筛 埃氏筛O(nloglogn),这 ...
- 题解报告:poj 2689 Prime Distance(区间素数筛)
Description The branch of mathematics called number theory is about properties of numbers. One of th ...
- HDU 1016 Prime Ring Problem (素数筛+DFS)
题目链接 题意 : 就是把n个数安排在环上,要求每两个相邻的数之和一定是素数,第一个数一定是1.输出所有可能的排列. 思路 : 先打个素数表.然后循环去搜..... #include <cstd ...
- Bi-shoe and Phi-shoe LightOJ - 1370(数论+素数筛)
题目链接:https://vjudge.net/problem/LightOJ-1370 题意:给你N个欧拉函数值,找出每一个大于等于该欧拉函数值的数,并且要求相加和最小. 题解:因为素数i的欧拉函数 ...
- [POJ268] Prime Distance(素数筛)
/* * 二次筛素数 * POJ268----Prime Distance(数论,素数筛) */ #include<cstdio> #include<vector> using ...
- codeforces 414A A. Mashmokh and Numbers(素数筛)
题目链接: A. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input ...
- POJ2689:Prime Distance(大数区间素数筛)
The branch of mathematics called number theory is about properties of numbers. One of the areas that ...
- POJ 3126 Prime Path (bfs+欧拉线性素数筛)
Description The ministers of the cabinet were quite upset by the message from the Chief of Security ...
随机推荐
- TestNG指南
转载自:http://blog.csdn.net/bigapplestar/article/details/7300137 今天突然收到通知,统一改用TestNG写测试用例,开始查这方面的资料,学习一 ...
- 赶快收藏!16款最流行的 JavaScript 框架
下面为大家介绍 16款最流行的 JavaScript 框架,赶快收藏! 1. jQuery – Javascript框架 jQuery 是最流行的 JavaScript 框架,它简化了HTML 文档遍 ...
- 【BZOJ】3302: [Shoi2005]树的双中心 && 2103: Fire 消防站 && 2447: 消防站
[题意]给定带点权树,要求选择两个点x,y,满足所有点到这两个点中较近者的距离*点权的和最小.n<=50000,h<=100. [算法]树的重心 [题解]代码参考自:cgh_Andy 观察 ...
- c++都忘记了,看了看那本发黄的C++primer,还是要去翻下了
char *s="string"和char s[]="string"的区别 void main() { char* pStr1 = "Hello!&q ...
- gcc 随笔
将几个文件编译成一个动态库 libtest.so gcc test_a.c test_b.c test_c.c -fPIC -shared -o libtest.so 将test.c与动态库libte ...
- RabbitMQ使用简记
RabbitMQ是什么 MQ全称为Message Queue, 即消息队列.MQ是一种应用程序对应用程序的通信方法.应用程序通过读写出入队列的消息(针对应用程序的数据)来通信,而无需专用连接来链接它们 ...
- 小程序_请求封装network
在utils目录下创建network.js文件封装请求 封装的network.js: //模块一,全局变量 let urlList = { host: 'http://47.106.25.53/', ...
- 安装Docker-ce
Docker Engine改为Docker CE(社区版) 它包含了CLI客户端.后台进程/服务以及API.用户像以前以同样的方式获取.Docker Data Center改为Docker EE(企业 ...
- Java Spring boot 企业微信点餐系统
欢迎关注我的微信公众号:"Java面试通关手册" 回复关键字" springboot "免费领取(一个有温度的微信公众号,期待与你共同进步~~~坚持原创,分享美 ...
- arch点击硬盘无法挂载
出现问题如下 在使用xfce4桌面的时候在点击硬盘图标时可以挂载虽然要求你输入root密码 但是在使用openbox的时候点击硬盘图标却出现如下提示,权限的问题 Not authorized to p ...