zoukankan      html  css  js  c++  java
  • F

    /**
    题目:F - Goldbach`s Conjecture
    链接:https://vjudge.net/contest/154246#problem/F
    题意:对一个大于2的偶数n,找有多少种方法使两个素数的和为n;保证素数a<=b; a+b==n; a,b都为素数。
    思路:直接暴力,为了避免内存超限,用bool类型判断素数。
    */
    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn = 1e7+10;
    bool flag[maxn];
    int prime[700010];
    int z;
    void init()
    {
        z = 0;
        for(ll i = 2; i<maxn; i++){
            if(flag[i]==false){
                prime[z++] = i;
                for(ll j = i*i; j < maxn; j+=i){
                    flag[j] = true;
                }
            }
        }
        //cout<<"z = "<<z<<endl;
    }
    int main()
    {
        init();
        int T, n, cas=1;
        cin>>T;
        while(T--)
        {
            scanf("%d",&n);
            int cnt = 0;
            for(int i = 0; prime[i]*2<=n; i++){
                if(flag[n-prime[i]]==false){
                    cnt++;
                }
            }
            printf("Case %d: %d
    ",cas++,cnt);
        }
        return 0;
    }
  • 相关阅读:
    js中replace的正则替换
    ios沙盒路径
    Android开源框架
    小知识点
    __NSCFConstantString && __NSPlaceholderDictionary
    iq 格式分析
    C 函数
    Xcode报错
    XMPP Server
    H5网站借鉴
  • 原文地址:https://www.cnblogs.com/xiaochaoqun/p/6618548.html
Copyright © 2011-2022 走看看