Lightoj 1259 Goldbach ' s conjecture water problem

Source: Internet
Author: User



Don't want to talk.


#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 water problem


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.