当前位置:网站首页>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;
}
边栏推荐
- 【转载】STM32 GPIO类型
- WasmEdge 0.10.0 发布!全新的插件扩展机制、Socket API 增强、LLVM 14 支持
- The maximum number of Rac open file descriptors, and the processing of hard check failure
- Sword finger offer 30 Stack containing min function
- B_ QuRT_ User_ Guide(26)
- Not so Mobile
- Tree
- JS rounding tips
- [reprint] STM32 GPIO type
- Case tool
猜你喜欢

webrtc优势与模块拆分
![[learning notes] matroid](/img/e3/4e003f5d89752306ea901c70230deb.png)
[learning notes] matroid

Discussion on the application of GIS 3D system in mining industry

Love analysis released the 2022 love analysis · it operation and maintenance manufacturer panorama report, and an Chao cloud was strongly selected!

JS rounding tips

Reverse mapping of anonymous pages

About using font icons in placeholder
![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...

Installing mysql5.7 under Windows

Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
随机推荐
The maximum number of Rac open file descriptors, and the processing of hard check failure
Basic twelve style classes for duilib
Tree
[go ~ 0 to 1] on the first day, June 24, variables, conditional judgment cycle statement
抖音服务器带宽有多大,才能供上亿人同时刷?
[cloud native | kubernetes] in depth understanding of pod (VI)
How do people over 40 allocate annuity insurance? Which product is more suitable?
Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu
[go ~ 0 to 1] the next day, June 25, switch statement, array declaration and traversal
The micro kernel zephyr is supported by many manufacturers!
CloudCompare&PCL 点云裁剪(基于封闭曲面或多边形)
Case tool
罗氏线圈工作原理
DELL R730服务器开机报错:[XXX] usb 1-1-port4: disabled by hub (EMI?), re-enabling...
Unity gets the coordinate point in front of the current object at a certain angle and distance
爱分析发布《2022爱分析 · IT运维厂商全景报告》 安超云强势入选!
Children's unit of 2022 Paris fashion week ended successfully at Wuhan station on June 19
js取整的小技巧
Installing MySQL under Linux
Map. ToCharArray( ),Map. getOrDefault(). Map. charAt()