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 ...
随机推荐
- npm 的使用指南
npm 使用指南 因为有写关于node.js的配置的博客,还有node和gulp的前端信息配置使用,其中有很多命令都用到了npm.所以这里要着重介绍一下npm. 1 npm介绍 npm(mode pa ...
- hdu 4940 Destroy Transportation system (无源汇上下界可行流)
Destroy Transportation system Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 ...
- 2049: [Sdoi2008]Cave 洞穴勘测
2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec Memory Limit: 259 MB Submit: 7475 Solved: 3499 [Submi ...
- Ping命令网络监测
按照由近到远原则: 1. ping 127.0.0.1 先检查TCP/IP协议栈是否正常. 2. ping 本地ip 检查网卡是否工作正常. 3. ping 网关地址 检查和网关连接性. 4. pin ...
- 前端观察:HTML5做得好,收入不比 iOS 差
谷歌奋进的绿色机器人超过了苹果的市场占有率,这一市场现象,导致了愈来愈多的开发者转投html5的怀抱.而HTML5将成为开发者拥抱同时拥抱Android和IOS的不二法门. 根据著名移动生态系统分析公 ...
- 【leetcode 简单】第三十三题 验证回文串
给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写. 说明:本题中,我们将空字符串定义为有效的回文串. 示例 1: 输入: "A man, a plan, a c ...
- Impala笔记之通用命令
help help命令用于查询其它命令的用法 [quickstart.cloudera:21000] > help select; Executes a SELECT... query, fet ...
- CTF线下赛AWD套路小结
近打了2场CTF线下赛,把AWD模式中的一些小套路做一些总结,本人web狗,二进制部分就不班门弄斧了. 一. AWD模式简介 AWD:Attack With Defence,比赛中每个队伍维护多台服务 ...
- 38 - 网络编程-socketserver
目录 1 socket编程弊端 2 SocketServer模块 2.1 服务器类 2.2 Mixin类 2.3 RequestHandlerClass是啥 2.4 编程接口 3 实现EchoServ ...
- ASP.NET Core 2.0 MVC 发布部署--------- linux安装.NET CORE SDK具体操作链接以及操作总细节
具体链接:https://www.microsoft.com/net/learn/get-started/linuxubuntu 如下图: