POJ 2262 Goldbach's Conjecture 数学常识 难度:0

题目链接:http://poj.org/problem?id=2262

哥德巴赫猜想肯定是正确的

思路:

  筛出n范围内的所有奇质数,对每组数据试过一遍即可,

  为满足b-a取最大,a取最小

时空复杂度分析:

  在1e6内约有8e4个奇质数,因为a <= b,时间复杂度在T*4e4+1e6等级.一般T为1e3,足以承受

  空间复杂度为1e6,足以承受

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 const int maxn = 1e6 + 6;
 6 int n;
 7 bool ntp[maxn];
 8 int prime[maxn],cnt;
 9 void judgeprime()
10 {
11     for(int i = 3;i < maxn;i += 2)
12     {
13         if(ntp[i])continue;
14         prime[cnt++] = i;
15         for(int j = 3;j * i < maxn;j += 2)
16         {
17             ntp[i * j] = true;
18         }
19     }
20
21 }
22
23 int main()
24 {
25     judgeprime();
26     while(scanf("%d",&n)==1 && n)
27     {
28         for(int i = 0;i < cnt && i < n / 2;i++)
29         {
30             if(!ntp[n - prime[i]])
31             {
32                 printf("%d = %d + %d\n",cnt,prime[i],n - prime[i]);
33                 break;
34             }
35         }
36     }
37     return 0;
38 }

POJ 2262 Goldbach's Conjecture 数学常识 难度:0

时间: 2024-12-27 16:20:42

POJ 2262 Goldbach's Conjecture 数学常识 难度:0的相关文章

poj 2262 Goldbach&#39;s Conjecture

Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 39353   Accepted: 15077 Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conject

POJ 2262 Goldbach&#39;s Conjecture (素数判断)

Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37693   Accepted: 14484 Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conject

POJ 2262 Goldbach&#39;s Conjecture (求解素数的一般筛和线性筛)

Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 40944   Accepted: 15664 Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conject

POJ 2262 Goldbach&#39;s Conjecture(素数相关)

POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示成两个素数相加和的形式.如果存在多组解,请输出两个素数差值最大的解. 分析: 首先我们用素数筛选法求出100W以内的所有素数. 筛选法求素数可见: http://blog.csdn.net/u013480600/article/details/41120083 对于给定的数X,如果存在素数a+素数b

POJ 2262 Goldbach&#39;s Conjecture(素数筛选法)

Description In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture: Every even number greater than 4 can be written as the sum of two odd prime numbers. For example: 8 =

POJ 2262 Goldbach&amp;#39;s Conjecture(素数相关)

POJ 2262 Goldbach's Conjecture(素数相关) http://poj.org/problem?id=2262 题意: 给你一个[6,1000000]范围内的偶数,要你将它表示成两个素数相加和的形式.假设存在多组解,请输出两个素数差值最大的解. 分析: 首先我们用素数筛选法求出100W以内的全部素数. 筛选法求素数可见: http://blog.csdn.net/u013480600/article/details/41120083 对于给定的数X,假设存在素数a+素数b

Poj 2262 / OpenJudge 2262 Goldbach&#39;s Conjecture

1.Link: http://poj.org/problem?id=2262 http://bailian.openjudge.cn/practice/2262 2.Content: Goldbach's Conjecture Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37791   Accepted: 14536 Description In 1742, Christian Goldbach, a German a

POJ 2909 Goldbach&#39;s Conjecture(简单题)

[题意简述]:输入一个数,输出有几对素数对可以使他们的和正好等于这个数 [分析]:暴力打表,再暴力循环求解 //268K 125Ms #include<iostream> using namespace std; #define N 35000 // 2^15 bool isprime[N]; int prime[N],nprime;//prime[N]用来存储素数,nprime是此时一共有多少素数 void doprime(int n) { int i,j; nprime = 1; mems

POJ 2909 Goldbach&#39;s Conjecture

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10333   Accepted: 6118 Description 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