Semi-prime H-numbers
题目描述形如4n+1的数被称为“H数”,乘法在“H数”集合内为封闭的。因数只有1和本身的数叫“H素数”(不包括1),其余叫“H合数”。一个“H合成数”能且只能分解为两个“H素数”。求0·h内的“H合成数”个数。
分析:可以根据同余理论筛素数。
如果一个数x为“H素数”,5*x+4*x*j一定是“H合数”
标记合数,找到素数就把它的倍数处理打上合数标记。
最后要统计一下。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<string>
using namespace std;
#define M 1000001+16
bool he[M],hech[M];
int su[M],ans[M];
long long tot;
int main()
{
int i,j;
for( i=;i<M;i+=)
{
if(he[i]) continue;//合数跳过
su[++tot]=i;
for(j=i*;j<M;j+=i*)//素数的推论,找合数
he[j]=true;
}
for(i=;i<=tot;i++)
for(j=;j<=i&&su[i]*su[j]<M;j++)
hech[su[i]*su[j]]=true;
for(i=;i<M;i++)
ans[i]=ans[i-]+hech[i];
int h;
scanf("%d",&h);
while(h)
{
printf("%d %d\n",h,ans[h]);
scanf("%d",&h);
}
return ;
}
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 ...
随机推荐
- Java网络编程InetAddress类
InetAddress用来代表IP地址.一个InetAdress的对象就代表着一个IP地址, getByName(String host):在给定主机名的情况下确定主机的 IP 地址,主机名可以是机器 ...
- [ZJOI 2012] 网络
[题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2816 [算法] 对每种颜色的边建一棵LCT , 维护联通性即可 时间复杂度 : O( ...
- 全民nib
1.为任何组件创建nib文件 那么如何通过XIB来创建自己的个性化的class呢. 1.Add----New Filss---Cocoa Touch Classes---Object-C Class ...
- HDU 1394 树状数组+离散化求逆序数
对于求逆序数问题,学会去利用树状数组进行转换求解方式,是很必要的. 一般来说我们求解逆序数,是在给定一串序列里,用循环的方式找到每一个数之前有多少个比它大的数,算法的时间复杂度为o(n2). 那么我们 ...
- 关于数组array的一些误区
$arr1 = array(1,2,3,4); $arr2 = array(5,6,7,8,9,10); var_dump ( $arr1 + $arr2); //输出数组形式的(1,2,3,4 ...
- CF-805C
C. Find Amir time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- g2o扩展,然后重新编译生成新库。
orb作者有g2o扩展,g2o原作者也有g2o扩展,等各项基本功扎实以后,考虑把他们整合在一起,再加上高博扩展的g2o,统一cmake,make,然后能make install 正常使用,就最好了.
- UVa 557 Burger (概率+递推)
题意:有 n 个牛肉堡和 n 个鸡肉堡给 2n 个客人吃,在吃之前抛硬币来决定吃什么,如果剩下的汉堡一样,就不用投了,求最后两个人吃到相同的概率. 析:由于正面考虑还要要不要投硬币,太麻烦,所以我们先 ...
- iOS 使用cocoapods导入ReactiveCocoa和ReactiveObjC框架
cocoapods使用 ReactiveObjC -- 对应的是RAC的OC版本,最新3.1.0版本. ReactiveCocoa--对应的是RAC的swift版本,最新7.1.0版本. 1.纯OC项 ...
- bat 批处理之提取带有关键字的整行数据
用于在log中检索出insert sql语句,主要用于数据恢复 前言: a.txt 里面存放的是 需要查找的关键字 b.bat limian 存放的是执行程序 生成的文件存放在 c.txt(自动创建) ...