当前位置:网站首页>Goldbach`s Conjecture
Goldbach`s Conjecture
2022-06-28 08:35:00 【Angeliaaa】
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.
Input
Input starts with an integer T (≤ 300), denoting the number of test cases.
Each case starts with a line containing an integer n (4 ≤ n ≤ 107, n is even).
Output
For each case, print the case number and the number of ways you can express n as sum of two primes. To be more specific, we want to find the number of (a, b) where
1) Both a and b are prime
2) a + b = n
3) a ≤ b
Sample Input
2
6
4
Sample Output
Case 1: 1
Case 2: 1
Note
1. An integer is said to be prime, if it is divisible by exactly two different integers. First few primes are 2, 3, 5, 7, 11, 13...
The question : Give several sets of test data , Each group gives one n, ask n A sum that can be divided into pairs of primes .
Ideas : Progressiveness a prime number makes a table , All primes in the data range are stored in a number , Of course, it has been arranged from small to large , Then from the first in the array 1 To the last convenience , If n Subtracting the value of this element is a prime number num++, If the element is greater than or equal to n/2+1, End convenience . Output num The value of the can . The code is as follows :
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
bool a[10000001];
int prime[666666];
int main()
{
int i,j,h,n,T,num,k=1,l=0;
for(i=2; i<=10000000; i++)
{
if(a[i]==false)
{
prime[l++]=i;
for(j=i+i; j<=10000000; j=j+i)
a[j]=true;
}
}
a[0]=a[1]=true;
scanf("%d",&T);
while(T--)
{
num=0;
scanf("%d",&n);
for(i=0; i<l; i++)
{
if(prime[i]>=n/2+1)
break;
h=n-prime[i];
if(a[h]==false)
{
num++;
}
}
printf("Case %d: %d\n",k++,num);
}
return 0;
}
边栏推荐
- Infinite penetration test
- PLSQL installation under Windows
- PMP从报考到拿证基本操作,了解PMP必看篇
- Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
- Installing mysql5.7 under Windows
- ffmpeg推流报错Failed to update header with correct duration.
- [go ~ 0 to 1] the next day, June 25, switch statement, array declaration and traversal
- How do individuals open accounts to speculate in stocks? Is online account opening safe?
- Super Jumping! Jumping! Jumping!
- Anniversary party
猜你喜欢
![Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...](/img/90/425965ca4b3df3656ce2a5f4230c4b.jpg)
Dell r730 server startup error: [xxx] USB 1-1-port4: disabled by hub (EMI?), re-enabling...

抖音服务器带宽有多大,才能供上亿人同时刷?

与普通探头相比,差分探头有哪些优点

What is the bandwidth of the Tiktok server that can be used by hundreds of millions of people at the same time?

In flood fighting and disaster relief, the city donated 100000 yuan of love materials to help Yingde

Reverse mapping of anonymous pages

关于如何在placeholder中使用字体图标

Set the icon for the title section of the page

AI chief architect 8-aica-gao Xiang, in-depth understanding and practice of propeller 2.0

Comment supprimer le crosstalk SiC MOSFET?
随机推荐
B_ QuRT_ User_ Guide(29)
Robot Rapping Results Report
Set the encoding of CMD to UTF-8
CloudCompare&PCL 点云SVD分解
What are the advantages of a differential probe over a conventional probe
RAC enable archive log
Set the icon for the title section of the page
Understanding of CUDA, cudnn and tensorrt
[learning notes] matroid
安装nrm后,使用nrm命令报错internal/validators.js:124 throw new ERR_INVALID_ARG_TYPE(name, ‘string‘, value)
爱分析发布《2022爱分析 · IT运维厂商全景报告》 安超云强势入选!
[go ~ 0 to 1] on the first day, June 24, variables, conditional judgment cycle statement
[learning notes] search
PMP从报考到拿证基本操作,了解PMP必看篇
How do people over 40 allocate annuity insurance? Which product is more suitable?
How to choose an account opening broker? Is it safe to open an account online?
Sword finger offer 30 Stack containing min function
Robot Rapping Results Report
Solve NPM err! Unexpected end of JSON input while parsing near
On the solution of insufficient swap partition