UVA 11105(p345)----Semi-prime H-numbers
2016-02-27 13:31
447 查看
#include<iostream> #include<cstdio> #include<vector> #include<cstring> #include<algorithm> using namespace std; const int maxn=250000; typedef long long LL; vector<int> hp; vector<LL> ans; int v[maxn*4+50]; int h,vis[maxn*4+50]; void prepare() { memset(v,1,sizeof(v)); for(int i=1; i<=maxn; i++) if(v[i*4+1]) { hp.push_back(i*4+1); for(int j=2*(i*4+1);j<=(maxn*4+1);j+=(i*4+1)) v[j]=0; } } int main() { prepare(); while(scanf("%d",&h)==1&&h) { int cnt=0; memset(vis,0,sizeof(vis)); for(int i=0;i<hp.size();i++) { if(hp[i]*hp[i]>h) break; for(int j=i;j<hp.size();j++) { int tmp=hp[i]*hp[j]; if(tmp>h) break; if(vis[tmp]) continue; cnt++; vis[tmp]=1; } } printf("%d %d\n",h,cnt); } return 0; }
相关文章推荐
- ESP8266(二)NODEMCU——烧录固件
- springIOC
- DOS命令将黑框中查询到的信息保存到TXT等文件里
- Linux3.5内核对路由子系统的重构对Redirect路由以及neighbour子系统的影响
- Ambari,hadoop的配置,管理和监控项目入门
- UVA 11093(p246)----Just Finish it up
- 线程池的学习与深入研究
- Emmet的高级功能与使用技巧
- 【LeetCode】 Populating Next Right Pointers in Each Node 全然二叉树
- STL中string的基本用法范例
- 通过hashmap实现统计字符串数组中某个字符串出现的次数的方法
- Android之ListView
- 如何查看自己电脑的IP和网络运营商
- poj Babelfish 2503 (字符串模拟)
- HDU 3416 Marriage Match IV(最短路+最大流)
- UVA 11054(p237)----Wine trading in Gergovia
- 使用HashMap做一个缓存案例【缓存一张图片】
- [神经网络]2.1-How the backpropagation algorithm works-Warm up: a fast matrix-based approach ...(翻译)
- 7.1 itertools--高效循环的创建函数
- 写一个函数,尽可能高效地从标准URL里取出文件的扩展名(新浪)