LightOJ 1259 Goldbach`s Conjecture
2015-10-01 15:21
585 查看
题意:
求1e7内的哥德巴赫猜想,找出某个数可以由几对素数相加得。思路:
直接素数打表暴力枚举即可。代码:
#define N 11234567 int n,m,sum; bool mark ; int pri[N/10],cnt; void SP() { cnt=0; memset(mark,true,sizeof(mark)); mark[0]=mark[1]=false; for(int i=2;i<N;i++) { if(mark[i]) pri[cnt++]=i; for (int j=0;(j<cnt)&&(i*pri[j]<N);j++) { mark[i*pri[j]]=false; if (i%pri[j]==0) break; } } } int main() { int i,j,k,kk,t,x,y,z; SP(); scanf("%d",&k); kk=0; while(k--) { scanf("%d",&n); for(sum=0,i=0;i<cnt&&pri[i]*2<=n;i++) if(mark[n-pri[i]]) sum++; printf("Case %d: %d\n",++kk,sum); } return 0; }
相关文章推荐
- Go 语言并发笔记
- codeforces #322 div 2 D. Three Logos (枚举)
- Django CSRF原理分析
- Codeforces Round #322 (Div. 2) D. Three Logos 模拟
- The following SDK component was not installed: extra-google-m2repository
- Django基础(一)
- God of War - HDU 2809(状态压缩+模拟)
- go语言之并发
- Django模板系统(非常详细)
- 使用Google Volley框架访问服务端,为Listview加载图片。
- golang echo livereload
- EGORefreshTableHeaderView使用方法(二)
- EGORefreshTableHeaderView、EGORefreshTableFooterView 列表下拉/上拉刷新: (一)
- Mongo 数据模型介绍
- golang 的 import理解实验
- go语言内存分配之TCMalloc
- Google地图实现
- Codeforces Round #322 D Three Logos
- GOOGLE MAP API 如何通过经纬度获取地址信息?
- Google Maps API V3学习一(获取地图坐标与街道地址)