zoukankan      html  css  js  c++  java
  • LightOJ

    链接:

    https://vjudge.net/problem/LightOJ-1259

    题意:

    Goldbach's conjecture is one of the oldest unsolved problems in number theory and in all of mathematics. It states:

    Every even integer, greater than 2, can be expressed as the sum of two primes [1].

    Now your task is to check whether this conjecture holds for integers up to 107.

    思路:

    素数表,然后暴力。

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #include<math.h>
    #include<vector>
    #include<map>
    
    using namespace std;
    typedef long long LL;
    const int INF = 1e9;
    
    const int MAXN = 1e7+10;
    const int MOD = 1e9+7;
    
    bool IsPrime[MAXN];
    int Prime[1000010];
    int n, tot;
    
    void Init()
    {
        memset(IsPrime, 0, sizeof(IsPrime));
        IsPrime[1] = 1;
        tot = 0;
        for (int i = 2;i < MAXN;i++)
        {
            if (IsPrime[i] == 0)
                Prime[++tot] = i;
            for (int j = 1;j <= tot && i*Prime[j] < MAXN;j++)
            {
                IsPrime[i*Prime[j]] = 1;
                if (i%Prime[j] == 0)
                    break;
            }
        }
    }
    
    int main()
    {
        Init();
        int t, cnt = 0;
        scanf("%d", &t);
        while(t--)
        {
            printf("Case %d:", ++cnt);
            scanf("%d", &n);
            int sum = 0;
            for (int i = 1;i <= tot && Prime[i] <= n/2;i++)
            {
                if (IsPrime[n-Prime[i]] == 0)
                    sum++;
            }
            printf(" %d
    ", sum);
        }
        
        return 0;
    }
    
  • 相关阅读:
    ivew-admin 导入excel
    ivew Upload 上传时附带的额外参数
    工厂方法模式
    简单工厂模式
    webpack (1)
    商品格子
    合同签名
    展示图片数组
    使用egg.js和egg-sequelize连接mysql
    egg 连接mysql 在mysql 插入数据
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11846333.html
Copyright © 2011-2022 走看看