【POJ 3292】 Semi-prime H-numbers
【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的更多相关文章
- BZOJ 2287: 【POJ Challenge】消失之物( 背包dp )
虽然A掉了但是时间感人啊.... f( x, k ) 表示使用前 x 种填满容量为 k 的背包的方案数, g( x , k ) 表示使用后 x 种填满容量为 k 的背包的方案数. 丢了第 i 个, 要 ...
- 【POJ 1741】Tree
Tree Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 11570 Accepted: 3626 Description ...
- 2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 553 Solved: 230[Submit][ ...
- 【POJ 3140】 Contestants Division(树型dp)
id=3140">[POJ 3140] Contestants Division(树型dp) Time Limit: 2000MS Memory Limit: 65536K Tot ...
- 【POJ 1275】 Cashier Employment(差分约束系统的建立和求解)
[POJ 1275] Cashier Employment(差分约束系统的建立和求解) Cashier Employment Time Limit: 1000MS Memory Limit: 10 ...
- 【POJ 2486】 Apple Tree(树型dp)
[POJ 2486] Apple Tree(树型dp) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8981 Acce ...
- 【POJ 2942】Knights of the Round Table(双联通分量+染色判奇环)
[POJ 2942]Knights of the Round Table(双联通分量+染色判奇环) Time Limit: 7000MS Memory Limit: 65536K Total Su ...
- 【POJ 2750】 Potted Flower(线段树套dp)
[POJ 2750] Potted Flower(线段树套dp) Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4566 ...
- 【POJ 2195】 Going Home(KM算法求最小权匹配)
[POJ 2195] Going Home(KM算法求最小权匹配) Going Home Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
随机推荐
- android 之 ListView相关
ListView是一种列表视图,其将ListAdapter所提供的各个控件显示在一个垂直且可滚动的列表中.需要注意的为创建适配器并将其设置给ListView. 1.ArrayAdapter Array ...
- vc调试大全
一.调试基础 调试快捷键 F5: 开始调试 Shift+F5: 停止调试 F10: 调试到下一句,这里是单步跟踪 F11: 调试到下一句,跟进函数内部 Shift+F11: 从当前函数中跳 ...
- Mac版有道云笔记不能自动同步
删除本地资源文件夹 /Users/xxxx/Library/Containers/com.youdao.note.YoudaoNoteMac 直接删除整个文件夹,之后重新登录账号.
- [android 应用框架api篇] bluetooth
bluetooth接口 android.bluetooth.jar 官网网址: 接口类: https://developer.android.com/reference/android/bluetoo ...
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) 一夜回到小学生
我从来没想过自己可以被支配的这么惨,大神讲这个场不容易掉分的啊 A. Carrot Cakes time limit per test 1 second memory limit per test 2 ...
- Result实现类
package org.apache.struts2.dispatcher; import com.opensymphony.xwork2.ActionInvocation; import com.o ...
- Linux硬件配置信息
在网上找了N久,发现了一篇不错的文档,转载一下: 1.查看机器所有硬件信息: dmidecode |more dmesg |more 这2个命令出来的信息都非常多,所以建议后面使用"|m ...
- BZOJ 3749: [POI2015]Łasuchy【动态规划】
Description 圆桌上摆放着n份食物,围成一圈,第i份食物所含热量为c[i]. 相邻两份食物之间坐着一个人,共有n个人.每个人有两种选择,吃自己左边或者右边的食物.如果两个人选择了同一份食物, ...
- 刷题总结:最长公共字串(spoj1811)(后缀自动机)
题目: 就不贴了吧···如题: 题解: 后缀自动机模版题:没啥好说的···· 代码: #include<iostream> #include<cstdio> #include& ...
- cf21D Traveling Graph
You are given undirected weighted graph. Find the length of the shortest cycle which starts from the ...