题目描述形如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的更多相关文章

  1. (全国多校重现赛一) H Numbers

    zk has n numbers a1,a2,...,ana1,a2,...,an. For each (i,j) satisfying 1≤i<j≤n, zk generates a new ...

  2. Prime Matrix(暴力出奇迹)

    Description You've got an n × m matrix. The matrix consists of integers. In one move, you can apply ...

  3. 河南省第十届省赛 Binary to Prime

    题目描述: To facilitate the analysis of  a DNA sequence,  a DNA sequence is represented by a binary  num ...

  4. Largest prime factor

    problem 3:Largest prime factor 题意:求600851475143的最大的质因数 代码如下: #ifndef PRO3_H_INCLUDED #define PRO3_H_ ...

  5. 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 ...

  6. codeforces 809E Surprise me!

    Tired of boring dates, Leha and Noora decided to play a game. Leha found a tree with n vertices numb ...

  7. Codeforces Round #324 (Div. 2)D. Dima and Lisa 数学(素数)

                                                     D. Dima and Lisa Dima loves representing an odd num ...

  8. BLUEZ测试报告

    测试小分队介绍: 马辰,李孟,罗凡 测试任务分类 帮助类 战斗类 道具类 敌军类 英雄类 地图类 AboutScene.h AchieveLayers.h GameLoading.h GameOver ...

  9. poj 3274 Gold Balanced Lineup(哈希 )

    题目:http://poj.org/problem?id=3274 #include <iostream> #include<cstdio> #include<cstri ...

  10. Jordan Lecture Note-8: The Sequential Minimal Optimization Algorithm (SMO).

    The Sequential Minimal Optimization Algorithm (SMO) 本文主要介绍用于解决SVM对偶模型的算法,它于1998年由John Platt在论文“Seque ...

随机推荐

  1. 【USACO】Optimal Milking

    题目链接 :        [POJ]点击打开链接        [caioj]点击打开链接 算法 : 1:跑一遍弗洛伊德,求出点与点之间的最短路径 2:二分答案,二分”最大值最小“ 3.1:建边,将 ...

  2. Json 不同语言的使用

    Javascript: 1.使用eval var parse_json_by_eval = function(str){ return eval('('+str+')'); } var value = ...

  3. checkbox的几种遍历方法

    html代码如下: <div> <input type="checkbox" name="ckb" value="1" / ...

  4. 1.6-1.10 使用Sqoop导入数据到HDFS及一些设置

    一.导数据 1.import和export Sqoop可以在HDFS/Hive和关系型数据库之间进行数据的导入导出,其中主要使用了import和export这两个工具.这两个工具非常强大, 提供了很多 ...

  5. python序列化之pickle,json,shelve

    模块 支持方法 说明 json dumps/dump loads/load 只能处理基本数据类型: 用于多种语言间的数据传输: pickle dumps/dump loads/load 支持pytho ...

  6. 利用python数据分析panda学习笔记之Series

    1 Series a:类似一维数组的对象,每一个数据与之相关的数据标签组成 b:生成的左边为索引,不指定则默认从0开始. from pandas import Series,DataFrame imp ...

  7. struts2注解的作用

    Struts2注解 1 Struts2注解的作用 使用注解可以用来替换struts.xml配置文件!!! 2 导包 必须导入struts2-convention-plugin-2.3.15.jar包, ...

  8. ThinkPHP3.2.3中,查询语句中in的使用方法。

    //删除分类 public function del(){ $cid = I('get.cid'); $cate = M('category')->field('cid,pid')->se ...

  9. 使用命令把类打成jar包

    测试用类 public class Hello { public static void main(String[] args) { System.out.println("hello wo ...

  10. Unity2016 Unity3D开发VR游戏的经验

    http://z.youxiputao.com/articles/8313 在4月12日的Unite 2016大会上,暴风魔镜高级产品经理吴涛分享他用Unity3D开发VR游戏的经验,以下为分享实录: ...