当前位置:网站首页>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;
}
边栏推荐
- 设置cmd的编码为utf-8
- Love analysis released the 2022 love analysis · it operation and maintenance manufacturer panorama report, and an Chao cloud was strongly selected!
- Superimposed ladder diagram and line diagram and merged line diagram and needle diagram
- What are the advantages of a differential probe over a conventional probe
- Not so Mobile
- Sword finger offer 03 Duplicate number in array
- PMP从报考到拿证基本操作,了解PMP必看篇
- Introduction, compilation, installation and deployment of Doris learning notes
- 罗氏线圈可以测量的大电流和频率范围
- [learning notes] shortest path + spanning tree
猜你喜欢
随机推荐
[learning notes] matroid
[untitled]
Kubernetes notes and the latest k3s installation introduction
Hidden scroll bar on PC
Priority of JS operator
爱分析发布《2022爱分析 · IT运维厂商全景报告》 安超云强势入选!
Loss损失函数
【.NET6】gRPC服务端和客户端开发案例,以及minimal API服务、gRPC服务和传统webapi服务的访问效率大对决
如何抑制SiC MOSFET Crosstalk(串扰)?
Selenium+chromedriver cannot open Google browser page
Selenium reptile
yaml json
Super Jumping! Jumping! Jumping!
隐私计算FATE-----离线预测
设置cmd的编码为utf-8
Robot Rapping Results Report
微内核Zephyr获众多厂家支持!
Usage record of Xintang nuc980: self made development board (based on nuc980dk61yc)
What are the advantages of a differential probe over a conventional probe
Solution: selenium common. exceptions. WebDriverException: Message: ‘chromedriver‘ execu

![[learning notes] matroid](/img/e3/4e003f5d89752306ea901c70230deb.png)







