【POJ 3292】 Semi-prime H-numbers



打个表

题意是1 5 9 13...这样的4的n次方+1定义为H-numbers

H-numbers中仅仅由1*自己这一种方式组成 即没有其它因子的 叫做H-prime

两个H-prime的乘积叫做H-semi-prime 另一个要求是H-semi-prime仅仅能由两个H-prime组成 即4个H-number 不可由3个或几个H-number构成

筛出来个满足题意的表 把每一个数内满足的个数存起来O(1)输出就可以

代码例如以下:

#include <iostream>
#include <cstdio>
#include <cstring> using namespace std;
const int sz = 1000001; int IsPrim[sz+1];
int p[sz];
int tp; void Init()
{
memset(IsPrim,0,sizeof(IsPrim));//H-numbers都初始化0 即默认都为H-prime
int i,j,cnt;
tp = 1;
for(i = 5; i <= sz; i += 4)
{
for(j = 5; j*i <= sz; j += 4)
{
if(IsPrim[i] || IsPrim[j])//两个数有一个不是H-prime 组合就不为H-semi-prime
IsPrim[i*j] = -1;
else IsPrim[i*j] = 1;//否则组合为H-semi-prime 注意 H-semi-prime就不为H-prime了 因为顺序枚举 后面遍历到的之前肯定会推断一下 故不会漏判
}
}
cnt = 0;
for(i = 1; i <= 1000001; ++i)
{
if(IsPrim[i] == 1) cnt++; p[tp++] = cnt;
}
} int main()
{
Init();
int h;
while(~scanf("%d",&h) && h)
{
h = (h-1)/4*4+1;
printf("%d %d\n",h,p[h]);
}
return 0;
}

【POJ 3292】 Semi-prime H-numbers的更多相关文章

  1. BZOJ 2287: 【POJ Challenge】消失之物( 背包dp )

    虽然A掉了但是时间感人啊.... f( x, k ) 表示使用前 x 种填满容量为 k 的背包的方案数, g( x , k ) 表示使用后 x 种填满容量为 k 的背包的方案数. 丢了第 i 个, 要 ...

  2. 【POJ 1741】Tree

    Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 11570   Accepted: 3626 Description ...

  3. 2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 553  Solved: 230[Submit][ ...

  4. 【POJ 3140】 Contestants Division(树型dp)

    id=3140">[POJ 3140] Contestants Division(树型dp) Time Limit: 2000MS   Memory Limit: 65536K Tot ...

  5. 【POJ 1275】 Cashier Employment(差分约束系统的建立和求解)

    [POJ 1275] Cashier Employment(差分约束系统的建立和求解) Cashier Employment Time Limit: 1000MS   Memory Limit: 10 ...

  6. 【POJ 2486】 Apple Tree(树型dp)

    [POJ 2486] Apple Tree(树型dp) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8981   Acce ...

  7. 【POJ 2942】Knights of the Round Table(双联通分量+染色判奇环)

    [POJ 2942]Knights of the Round Table(双联通分量+染色判奇环) Time Limit: 7000MS   Memory Limit: 65536K Total Su ...

  8. 【POJ 2750】 Potted Flower(线段树套dp)

    [POJ 2750] Potted Flower(线段树套dp) Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4566   ...

  9. 【POJ 2195】 Going Home(KM算法求最小权匹配)

    [POJ 2195] Going Home(KM算法求最小权匹配) Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

随机推荐

  1. Solr5.0.0 DIH之增量索引

    定时索引相关知识 增量更新需要配置个sql(deltaImportQuery.deltaQuery) deltaImportQuery="select * where id='${dih.d ...

  2. linux下ls出现文件的后缀有@,* ,/之类的解释

    ls -Fafptool*  img_maker*    lzcmp@     lzfgrep@   lzma*         lzmore*         node-pre-gyp@bower@ ...

  3. LeetCode 673. Number of Longest Increasing Subsequence

    Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...

  4. Impala Catalog Server StateStore 端口被占 无法启动问题

    最新版的Impala时候关闭的时候无法关闭 Catalog Server和StateStore后台进程,导致错误如下: --max_log_size= --minloglevel= --stderrt ...

  5. debian 9 安装AMD驱动

    目录 debian 9 安装AMD驱动 安装驱动之前: 安装驱动: 安装驱动之后: debian 9 安装AMD驱动 需求说明: 安装完成debian系统后独显驱动未安装 操作系统版本: kyeup@ ...

  6. numpy.clip(a, a_min, a_max, out=None)(values < a_min are replaced with a_min, and those > a_max with a_max.)

    numpy.clip(a, a_min, a_max, out=None) Clip (limit) the values in an array. Given an interval, values ...

  7. Ubuntu16.04 on ThinkPad E455 不能识别耳机 的解决方法

    去年 (2016) 2月份在ThinkPad E455 上安装了Ubuntu 14.04 LTS (dual boot with Windows 10, upgraded to Ubuntu 16.0 ...

  8. servlet分析

    Servlet生命周期分为三个阶段: 1,初始化阶段  调用init()方法 2,响应客户请求阶段 调用service()方法 3,终止阶段 调用destroy()方法 Servlet初始化阶段: 在 ...

  9. angular父子scope之间的访问

    1.子可以访问父的scope,也可以更新相同的scope,但父scope不会被刷新 2.父要访问子scope的方法

  10. idea下springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到

    接着上一章走呗:http://www.cnblogs.com/sxdcgaq8080/p/7712874.html 然后声明一点,下面打包的过程中,scope一直都是使用默认的范围 <!--用于 ...