POJ 3292.Semi-prime H-numbers
来源:互联网 发布:烟台青少年编程培训 编辑:程序博客网 时间:2024/06/02 03:55
题目:http://poj.org/problem?id=3292
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>#include <string.h>#include <bitset>#define INF 0xfffffff#define MAXN 100105using namespace std;int Hsp[250010];int cnt[250010];void table(){memset(Hsp,0,sizeof(Hsp));for(int i = 2; i <= 250009; i++){for(int j = 2; j <= i; j++){if(4*i*j-3*i-3*j+3>250009)break;if(Hsp[i]==0&&Hsp[j]==0)Hsp[4*i*j-3*i-3*j+3]=1;else Hsp[4*i*j-3*i-3*j+3]=2;}}cnt[1] = 0;for(int i = 2; i < 250010; i++){if(Hsp[i]==1)cnt[i]=cnt[i-1]+1;else cnt[i] = cnt[i-1];}}int main(){table();int n;while(cin>>n){if(n==0)break;cout<<n<<' '<<cnt[(n+3)/4]<<endl;}}总结: 打表. H-num分三种: Hp, Hsp, Hc. 打表从小往大打, 第一次遇到的数都是Hp, 故首先全部置0, 代表是Hp. 然后两个两个数取出来, 如果两个都是Hp则乘积是Hsp, 标记为1, 否则就是Hc, 标记为2.
阅读全文
0 0
- POJ 3292.Semi-prime H-numbers
- POJ 3292.Semi-prime H-numbers
- Semi-prime H-numbers POJ
- POJ 3292 Semi-prime H-numbers
- poj 3292 Semi-prime H-numbers
- poj 3292 Semi-prime H-numbers
- POJ 3292 Semi-prime H-numbers
- poj-3292-Semi-prime H-numbers
- POJ 3292 Semi-prime H-numbers
- POJ 3292 Semi-prime H-numbers
- POJ-3292-Semi-prime H-numbers
- POJ 3292 Semi-prime H-numbers
- poj 3292 Semi-prime H-numbers
- POJ 3292 Semi-prime H-numbers
- POJ 3292--Semi-prime H-numbers
- POJ 3292 Semi-prime H-numbers
- POJ 3292 Semi-prime H-numbers
- poj 3292 Semi-prime H-numbers 筛数打表
- IntelliJ IDEA 学习笔记
- spring配置中<context:annotation-config> 和 <context:component-scan>区别
- dataGrid 删除行
- IndentationError: unindent does not match any outer indentation level
- 滑动变阻器改进AD输入电压(STM32)
- POJ 3292.Semi-prime H-numbers
- POJ1741 tree 【点分治】
- Python day2 总结
- postgresql操作
- Cmake “no cmake c_compiler could be found”,“无法打开输入文件”问题解决思路
- android 异步任务 设置 超时,使用handler更新通知
- ceph rbd 文件读写测试
- Linux中` `、$、$( ) 、${ } 的区别
- hadoop概述及集群搭建