奇数偶数之和c语言,[求助]一个偶数表示两个奇数之和。

本文介绍了一个18世纪数学猜想——哥德巴赫猜想,即每个大于4的偶数可以表示为两个奇数之和。展示了如何验证这一猜想对小于100万的偶数,并提供了样例输入和输出。

[求助]一个偶数表示两个奇数之和。

Goldbach's Conjecture

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 = 3 + 5. Both 3 and 5 are odd prime numbers.

20 = 3 + 17 = 7 + 13.

42 = 5 + 37 = 11 + 31 = 13 + 29 = 19 + 23.

Today it is still unproven whether the conjecture is right. (Oh wait, I have the proof of course, but it is too long to write it on the margin of this page.)

Anyway, your task is now to verify Goldbach's conjecture for all even numbers less than a million.

Input

The input will contain one or more test cases.

Each test case consists of one even integer n with 6 <= n < 1000000.

Input will be terminated by a value of 0 for n.

Output

For each test case, print one line of the form n = a + b, where a and b are odd primes. Numbers and operators should be separated by exactly one blank like in the sample output below. If there is more than one pair of odd primes adding up to n, choose the pair where the difference b - a is maximized. If there is no such pair, print a line saying "Goldbach's conjecture is wrong."

Sample Input

8

20

42

0

Sample Output

8 = 3 + 5

20 = 3 + 17

42 = 5 + 37

新学期开始了,同学们要掌握更多的知识啦。新的学期,新的开始,是是要给自己订个目标呢?比如数据结构期末考试考到八十分以上,自己的程序设计能力大幅度提高?新学期,脚踏实地的去努力,一定会有收获,碰到问题,别忘记周围有同学老师可以求助。 说起上学期学习C语言的时候,让你头疼的问题有没有很多?函数参数问题是是其中一项呢?在C语言中,参数传递的机制只有一种,就是值传送,值传送是实参的值传给形参,当形参改变,实参的值并修改。 如果想修改怎么办呢?小可爱们一定都知道了吧,我们的开课准备题目集里都给出来了呢。 用一句话总结就是,如果想在被调函数里改变主调函数变量的值,那就把变量的地址传过去,形参定义为指向该变量类型的指针。 比如主调函数是main函数,被调函数名为fun。 int b=4; void fun(int **p);//这里为什么是两个*,好晕啊!请阅读main中问题。 int main() { int a=3; int *p=&a; //如果想在fun函数里改变p的值,让p值为变量b的地址,参数应该有哪些呢?是是要把p的地址传过去? fun(&p);//p是一级指针,那形参应该是几级指针呢? ……//后面代码省略 } 看到这里,我猜可能会有晕乎乎的同学。 指针真让人头大,为了提高代码的可读性,聪明的计算机科学家想到了引用机制,可是这个引用机制,C语言没有,C++才能用。 引用是什么呢?是对变量起别名(弱弱问一句,看到别名这俩个字,是是很熟悉,我们学过对类型起别名,关键字是什么呢?) 既然是对变量起别名,那这个别名在声明的时候一定有所同。哪里同呢,就是在声明的时候使用引用符号&。 这个符号&作用可真多,在声明的时候表示引用,在已有一个操作数的时候表示取地址,在两个操所数的时候表示位运算中的按位与。 如果在被调函数中想修改主调函数里的变量值,那形参直接是实参的别名,对形参修改,实参就直接改了。(哈哈,太好了,用指针了) 那我们开课准备的交换函数用引用处理就很简单了。 #include <stdio.h> void mySwap(int&, int&); int main() { int a = 20,b = 30; mySwap(a, b); printf("a=%d,b=%d\n", a, b); return 0; } void mySwap(int &m, int &n)//m,n前有&,表明是引用参数,分别是a,b的别名 { int t = m; m = n; n = t; } 程序执行的结果a=30,b=20完成交换。 聪明的你,是是觉得还是引用比指针简单啊。过,我们要求指针引用都掌握。 那我们现在使用引用,完成一个简单的操作吧。 从键盘上输入n个正整数,求偶数的个数以及奇数。 输入格式: 输入两行,第一行输入正整数个数n(n<=100)。 第二行输入n个正整数,任意两个整数之间用一个空格分隔。 输出格式: 输出为两行,第一行表示偶数的个数。 第二行为奇数。 输入样例: 5 5 6 7 8 9 输出样例: 2 21 include<stdio.h> void solve(int n, 1 分 ); //n的值变,所以没定义为引用参数 int main() { int n,sum, cnt; scanf("%d",&n); //输入n的值 solve( 1 分 ); //处理 printf("%d\n%d",cnt,sum);//输出 return 0; } void solve(int n, 1 分 ) { sum=0;cnt=0; int num; for(int i=0;i<n;i++) { scanf("%d",&num); if(num&1) { 1 分 } else { 1 分 } } }
09-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值