传送门:

刷《数论一本通》时看到的题,简单记录一下。

题目大意(照抄书上的):形如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的更多相关文章

  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. CSS 颜色代码大全

    CSS颜色: 转载:http://www.cnblogs.com/axing/archive/2011/04/09/CSS.html

  2. jQuery经典学习笔记

    1.层次选择器: $("div> span") 获取div下的span元素 $(".one + div") 获取class为one的下一个div 2)过滤 ...

  3. Angular指令1

    Angular的指令 也就是directive,其实就是一WebComponent,以前端的眼光来看,好象很复杂,但是以后端的眼光来看,还是非常简单的.其实就是一个中等水平的类. var myModu ...

  4. js的bind方法

    转载:http://www.jb51.net/article/94451.htm http://www.cnblogs.com/TiestoRay/p/3360378.html https://seg ...

  5. memcache 安装

    1 下载两个文件 wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz wget http://www.monkey.org/ ...

  6. 求二叉树的宽度C语言版

    /*层次遍历二叉树,每一层遍历完成以后都重新插入特定的指针 (比如本例使用的特殊指针是数据元素为#,左右儿子为空的指针), 这样在每次访问到所指向数据为#的队列中的结点指针是就知道该指针是这层的末尾, ...

  7. Shell命令_文件系统常用命令df、du

    一.df(文件系统查看命令) [root@localhost ~]# df [选项] [挂载点] 选项: -a 显示所有的文件系统信息,包括特殊文件系统,如 /proc. /sysfs -h 使用习惯 ...

  8. hdu 4612 强连通

    题意:有一些联通的地方,如果2点间只有一条路径,这样的边叫做桥,现在让你添加一个桥,使最后的桥最少,问最少的桥使多少? 先求一次强连通分量,然后图就分成了几个块,将这几个块看做点,求出总共有多少条重建 ...

  9. 网络爬虫讲解(附java实现的实例)

    本文转载http://blog.csdn.net/luojinping/article/details/6870898 转载过来主要是防止想百度文库一样突然停止运作,导致很多文库丢失而无法找寻 网络蜘 ...

  10. shell中substr总结

    (1)awk中函数substr substr(源字符串,开始索引,长度)   开始索引以0开始 示例: awk '{$a=substr($0,0,2);print $a;}' filename 假设文 ...