UVa 686 Goldbach's Conjecture (II):哥德巴赫猜想

686 - Goldbach's Conjecture (II)

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=627

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. 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

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

完整代码:

/*0.015s*/

#include<cstdio>
#include<cmath>
const int maxn = 1 << 15;
const int m = (int)sqrt(maxn);  

bool vis[maxn];  

inline void cal_prime()
{
    int i, j;
    for (i = 2; i <= m; ++i)
        if (!vis[i])
            for (j = i * i; j < maxn; j += i)
                vis[j] = true;
}  

int main()
{
    cal_prime();
    int n, m, i, count;
    while (scanf("%d", &n), n)
    {
        count = 0, m = n >> 1;
        for (i = 2; i <= m; ++i)
            if (!vis[i] && !vis[n - i])
                ++count;
        printf("%d\n", count);
    }
    return 0;
}

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索numbers
, number
, The
, |II|IS|S排|排错|错|
, should
, 哥德巴赫猜想
, Conjecture
even
goldbach conjecture、uva lou s list、goldbach、kakeya conjecture、conjecture,以便于您获取更多的相关知识。

时间: 2024-08-03 08:56:28

UVa 686 Goldbach's Conjecture (II):哥德巴赫猜想的相关文章

UVa 543 Goldbach&#039;s Conjecture:素数&amp;amp;哥德巴赫猜想

543 - Goldbach's Conjecture Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=484 In 1742, Christian Goldbach, a German amateur mathematician, sent a letter

哥德巴赫猜想证明

public class Guess { public static boolean isPrime(int i) { // 判断参数i是否是素数,是则返回true反之则返回false int n; boolean flag = true; if (1 == i) // 1本身不是素数,因此需把这个特殊的数字抛出 flag = false; for (n = 2; n <= i - 1; n++) /* 判断i是否是素数的一个方法是看2-i-1之间有其因子(能被2整除),有则不是素数返回fals

URAL 1356 哥德巴赫猜想

题意:给出一个数,把它分解成几个素数相加的形式,要求分解出的素数的数量最小. 这题分情况讨论就可以了,首先需要知道哥德巴赫猜想即一个大于4的偶数可以分解成两个素数和的形式.其次需要知道奇数加奇数等于偶数,奇数减奇数等于偶数. 那么首先判断n是否是素数,如果是直接输出n就可以. 接下来判断如果n是奇数,那么先判断n-2是否是素数,如果是的话那么最小数量的素数和即n-2 与 2,如果不是那么肯定能减一个奇素数数得到一个偶数再分解成两个素数.这个奇素数首选肯定是3,因为3最小适合绝大多数情况. 如果n

年轻时迷上哥德巴赫猜想

福州新闻网讯许多人退休后会选择养鸟.养花.打门球.画画等方式休闲养性.不过,福清的林敦棋却有个很特别的爱好他对数字感兴趣,一有空就忙着研究探讨"大质数""大序数".在今年的<科技信息>等学术刊物上,他居然连续发表了6篇相关的专业文章,邻里都对其刮目相看.29日,林敦棋在家中翻出许多发黄的藏书.笔记以及曾经的演算手稿,饶有兴致地向记者讲述他迷上数字的历程. 年轻时迷上哥德巴赫猜想 林敦棋告诉记者,他研究"大质数""大序数&qu

新手求解答一下-验证哥德巴赫猜想成立

问题描述 验证哥德巴赫猜想成立 2000以内的正偶数都可以分解成两个素数之和,即验证哥德巴赫猜想对2000以内的正偶数成立(但我们还没学函数,只学了循环,要用C++编) 解决方案 验证哥德巴赫猜想验证"哥德巴赫猜想"

中关村金融创新破解“哥德巴赫猜想”

本报讯(记者王磊 刘世昕)科技型中小企业融资难一度被称为中关村的"哥德巴赫猜想",11月12日举行的2009中关村论坛为此找到了答案.据悉,在金融危机的背景下,中关村科技园区正在通过一系列"金融创新",逆市打造具有全球影响力的"头脑产业"中心. 据记者了解,首都科技金融综合改革试验区已经落户中关村.该试验区在3~5年内,将着力构建以股权投资机构为主体,以多层次资本市场体系为核心,以信用体系建设为基础,以财政资金为杠杆,综合运用银行.证券.保险.信

哥德巴赫猜想,c++,判断条件求助

问题描述 哥德巴赫猜想,c++,判断条件求助 程序体如下: #include using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop / int div(int a) ; int main(int argc, char* argv) { int a,b; for(a=4;a<=2000;a+=2){

c++验证哥德巴赫猜想_C 语言

哥德巴赫猜想是世界近代三大数学难题之一.1742年,由德国中学教师哥德巴赫在教学中首先发现的.1742年6月7日哥德巴赫把自己的多年实验证明写信给当时的大数学家欧拉,欧拉回信正式提出了以下两个猜想:a.任何一个大于 6的偶数都可以表示成两个素数之和.b.任何一个大于9的奇数都可以表示成三个素数之和. 这就是哥德巴赫猜想. 复制代码 代码如下: //任一大于2的偶数,都可表示成两个素数之和.#include<iostream>using namespace std;int prime(int n

UVa 10940 Throwing cards away II:约瑟夫问题

10940 - Throwing cards away II Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1881 Given is an ordered deck of n cards numbered 1 to n with card 1 at th