POJ3292 Semi-prime H-numbers
刷《数论一本通》时看到的题,简单记录一下。
题目大意(照抄书上的):形如4n+1的数被称为H数,乘法在H数组成的集合内是封闭的。在这个集合中是能被1和本身整除的数叫H-素数,其余的数被称为H合数,1个
H-合成数是一个能且只能被分解成两个H-素数乘积的H合数,求0-h内有多少个H合成数。
题解:
首先,两个H素数的乘积一定是H数,这个可以推导出来:

所以只要我们求出0-h内有多少个H素数,就可以得到本题的答案。根据同余原理我们知道如果i是素数,那么i(5+4x)必定不是H素数且一定是H数,那么就可以通过筛发求出本题的答案。
//POJ 3292
//by Cydiater
//2016.8.29
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <iomanip>
#include <ctime>
#include <cmath>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;
#define ll long long
#define up(i,j,n) for(int i=j;i<=n;i++)
#define down(i,j,n) for(int i=j;i>=n;i--)
;
;
const int oo=0x3f3f3f3f;
inline int read(){
,f=;
;ch=getchar();}
+ch-';ch=getchar();}
return x*f;
}
,N;
namespace solution{
void pret(){
memset(prime,,sizeof(prime));
memset(semi,,sizeof(semi));
memset(ans,,sizeof(ans));
;i<=LIM;i+=){
if(prime[i])continue;
Count[++cnt]=i;
;i*(*j+)<=LIM;j++)prime[i*(*j+)]=;
}
up(i,,cnt)up(j,,i)if(Count[i]*Count[j]>LIM)break;
;
up(i,,LIM)ans[i]=ans[i-]+semi[i];
}
void slove(){
)printf("%d %d\n",N,ans[N]);
}
}
int main(){
//freopen("input.in","r",stdin);
using namespace solution;
pret();
slove();
;
}
POJ3292 Semi-prime H-numbers的更多相关文章
- (全国多校重现赛一) H Numbers
zk has n numbers a1,a2,...,ana1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk generates a new ...
- Prime Matrix(暴力出奇迹)
Description You've got an n × m matrix. The matrix consists of integers. In one move, you can apply ...
- 河南省第十届省赛 Binary to Prime
题目描述: To facilitate the analysis of a DNA sequence, a DNA sequence is represented by a binary num ...
- Largest prime factor
problem 3:Largest prime factor 题意:求600851475143的最大的质因数 代码如下: #ifndef PRO3_H_INCLUDED #define PRO3_H_ ...
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- codeforces 809E Surprise me!
Tired of boring dates, Leha and Noora decided to play a game. Leha found a tree with n vertices numb ...
- Codeforces Round #324 (Div. 2)D. Dima and Lisa 数学(素数)
D. Dima and Lisa Dima loves representing an odd num ...
- BLUEZ测试报告
测试小分队介绍: 马辰,李孟,罗凡 测试任务分类 帮助类 战斗类 道具类 敌军类 英雄类 地图类 AboutScene.h AchieveLayers.h GameLoading.h GameOver ...
- poj 3274 Gold Balanced Lineup(哈希 )
题目:http://poj.org/problem?id=3274 #include <iostream> #include<cstdio> #include<cstri ...
- Jordan Lecture Note-8: The Sequential Minimal Optimization Algorithm (SMO).
The Sequential Minimal Optimization Algorithm (SMO) 本文主要介绍用于解决SVM对偶模型的算法,它于1998年由John Platt在论文“Seque ...
随机推荐
- React Native 在现有项目中的探路
移动开发中,native开发性能和效果上无疑是最好的. 但是在众多的情况下,native开发并不是最优的选择.当需求经常改动的时候,当预算有限的时候,当deadline很近的时候,native开发的成 ...
- web安全——应用(java)
简介 由于网络技术日趋成熟,黑客们也将注意力从以往对网络服务器的攻击逐步转移到了对web应用的攻击.据最新调查,信息安全有75%都发生在web应用而非网络层面. 场景 控制访问的权限.只让可以访问的访 ...
- 服务链(Service Chaining,or Service Function Chaining,SFC,功能服务链)
Software-configured service chaining provides the capability to dynamically include best-of-b ...
- matlab画图形函数 semilogx
matlab画图形函数 semilogx loglog 主要是学习semilogx函数,其中常用的是semilogy函数,即后标为x的是在x轴取对数,为y的是y轴坐标取对数.loglog是x y轴都取 ...
- js滚动到底部事件
window.innerHeight表示窗口高度 $(document).height()返回文档高度 $(document).scrollTop()返回滚动条与顶部的距离,在最上部时为0,在最下部时 ...
- python 2.7 简单模拟登陆网站
举个栗子,首先创建网络会话, 然后就可以用创建的session来访问网页了. session.get(URL) #-*- coding:utf-8 -*- import requests import ...
- Linux14.04安装Mysql Linux公社
今天在Ubuntu 14.04下安装MySQL,本来是去官网下载安装包来安装的,可是安装之后却不能用,估计是要配置吧,在网上搜了很多的资料,结果还是失败.所以只好在软件源中安装,这样就省去很多不必要的 ...
- hadoop,mapreduce---分布式计算
从图中可以看出,map阶段的shuffle: 例如word count,当内存缓冲区满的时候会写到磁盘,一个spill,每个spill,进行分区,排序,最后将同一个分区word合并在一起,写入到磁盘中 ...
- XAML: x:DeferLoadStrategy, x:Null
x:DeferLoadStrategy="Lazy" - 用于指定一个 UIElement 为一个延迟加载元素 x:Null - null 示例1.x:DeferLoadStrat ...
- sublime text 如何设置”在浏览器浏览“的快捷键
sublime text编辑器极其强大 ,但在刚开始用的时候,每次在浏览器中查看非得右键鼠标----”open in browser“,着实觉得麻烦....百度之,上面的方法有很多,但是根据我自己的经 ...