首页 > 数据库技术 > 详细

LightOJ 1259 Goldbach`s Conjecture 水题

时间:2016-04-12 22:15:41      阅读:205      评论:0      收藏:0      [点我收藏+]

不想说了

技术分享
#include <cstdio>
#include <iostream>
#include <ctime>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;
const int N=1e7+5;
const int INF=0x3f3f3f3f;
int cnt;
bool v[N];
int prime[700000];
void getprime(){
  for(int i=2;i*i<=N-5;++i)
    if(!v[i])
      for(int j=i*i;j<=N-5;j+=i)
        v[j]=1;
  for(int i=2;i<=N-5;++i)
  if(!v[i])prime[++cnt]=i;
}
int main()
{
    getprime();
    int cas=0,T;
    scanf("%d",&T);
    while(T--){
      int n;
      scanf("%d",&n);
      int pos=upper_bound(prime+1,prime+1+cnt,n/2)-prime;
      int ans=0;
      for(int i=1;i<pos;++i){
        if(!v[n-prime[i]])++ans;
      }
      printf("Case %d: %d\n",++cas,ans);
    }
    return 0;
}
View Code

 

LightOJ 1259 Goldbach`s Conjecture 水题

原文:http://www.cnblogs.com/shuguangzw/p/5384503.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!