zoukankan      html  css  js  c++  java
  • [暑假集训--数论]poj2909 Goldbach's Conjecture

    For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that

    n = p1 + p2

    This conjecture has not been proved nor refused yet. No one is sure whether this conjecture actually holds. However, one can find such a pair of prime numbers, if any, for a given even number. The problem here is to write a program that reports the number of all the pairs of prime numbers satisfying the condition in the conjecture for a given even number.

    A sequence of even numbers is given as input. There can be many such numbers. Corresponding to each number, the program should output the number of pairs mentioned above. Notice that we are interested in the number of essentially different pairs and therefore you should not count (p1, p2) and (p2, p1) separately as two different pairs.

    Input

    An integer is given in each input line. You may assume that each integer is even, and is greater than or equal to 4 and less than 215. The end of the input is indicated by a number 0.

    Output

    Each output line should contain an integer number. No other characters should appear in the output.

    Sample Input

    6
    10
    12
    0

    Sample Output

    1
    2
    1

    给个n>=6,问把n分成两个奇质数之和有几种方案

    直接暴力枚举其中一个是啥,只要不重复统计就行

     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #define LL long long
     5 using namespace std;
     6 inline LL read()
     7 {
     8     LL x=0,f=1;char ch=getchar();
     9     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    10     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    11     return x*f;
    12 }
    13 LL n;
    14 bool mk[200010];
    15 int p[200010],len;
    16 inline void getp()
    17 {
    18     for (int i=2;i<=200000;i++)
    19     {
    20         if (!mk[i])
    21         {
    22             p[++len]=i;
    23             for (int j=2*i;j<=200000;j+=i)mk[j]=1;
    24         }
    25     }
    26 }
    27 int main()
    28 {
    29     getp();
    30     while (~scanf("%lld",&n)&&n)
    31     {
    32         int ans=0;
    33         for (int i=1;p[i]*2<=n;i++)
    34             if (!mk[n-p[i]])ans++;
    35         printf("%d
    ",ans);
    36     }
    37 }
    poj 2909
  • 相关阅读:
    mysql 聚集函数 count 使用详解
    在Docker中使用kettle遇到的问题解决
    整取零存_字段级迁移工具
    快速修改MySQL字段类型
    数据仓库知识点梳理(4)
    五一节分享60多本免费AI电子书
    数据仓库知识点梳理(3)
    数据仓库知识点梳理(2)
    数据仓库知识点梳理(1)
    解决MacVim在macOS Catalina下字母显示不全的问题
  • 原文地址:https://www.cnblogs.com/zhber/p/7285405.html
Copyright © 2011-2022 走看看