哥德巴赫猜想

描述:

德国数学家哥德巴赫(Goldbach)在1725年写给欧拉(Euler)的信中提出了以下猜想:任何大于2的偶数都是两个素数之和(俗称为1+1)。
    我国数学家陈景润,在数论研究中对哥德巴赫猜想问题展开了精心的解析和科学的推算,证明了任何一个充分大的偶数,都可以表示一个素数加上顶多是两个素数的乘积,简称“1+2”。
    两个多世纪过去了,这一猜想仍然无法证明。试设计程序验证这一猜想是否成立。例如6 = 3 + 3,8 = 3 + 5. 现在请你写一个程序,当输入一个偶数n(6=<n<1000000)时,输出对应的满足条件的两个素数。
A letter from German mathematician Goldbach (Goldbach) to Euler (Euler) in 1729 proposed the following conjecture:
Any even number which is greater than 2 is the sum of prime numbers.
Although two centuries had gone,this conjecture can not be proven. Now try to design a program to certify this conjecture.
For example:6 = 3 + 3,8 = 3 + 5.

输入:

输入测例n满足6<= n <1000000,n为偶数。
Input an even which is between 6 and 1000000.

输出:

输出满足条件的数,形式为n = a + b,其中a和b为素数。如果存在多组素数a和b,则选择b-a最大的一组作为输出。如果不存在这样的素数a,b,输出"不符合猜想".
Output the results in the form of “n=a+b”(a and b are all prime number).If the results are more than one,then select the largest group of “a-b” .If don’t exist the matching prime number,output “Don’t match conjecture” .

输入样例:

8

输出样例:

8 = 3 + 5 提示:输出语句为printf("%d = %d + %d\n", a, b, c); 中间都有空格

#include<iostream>
using namespace std;
int main()
{
 int n,a,b,c,flag;
 cin>>n;
 for(a=2;a<n;a++)
 {
  flag=1;
  for(c=2;c<a;c++)
  {
   if(a%c==0)
   {
    flag=0;
   }
  }
  if(flag==1)
  {
   b=n-a;
   for(c=2;c<b;c++)
   {
    if(b%c==0)
    {
     flag=0;
     break;
    }
   }
   if(flag==1)
   {
    cout<<n<<" = "<<a<<" + "<<b<<endl;
    break;
   }
  }
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值