Rokua-Goldbach conjecture (upgraded version)-boss War-Getting started comprehensive Exercise 1

Source: Internet
Author: User

Topic BackgroundBackground1742 June 7 Goldbach wrote to the then great mathematician Euler, who formally proposed the following conjecture: any odd number greater than 9 can be expressed as the sum of 3 prime numbers. Prime numbers mean that there are no other approximate numbers except 1 and itself, such as 2 and 11 are prime numbers, and 6 are not prime numbers, because 6 have an approximate 1 and 6 in addition to the approximate 2 and 3. What needs to be specifically stated is that 1 is not prime. This is Goldbach conjecture. In his reply, Euler said he believed the conjecture was correct, but he could not prove it. Since then, this mathematical puzzle has aroused the attention of almost all mathematicians. Goldbach guess thus become a mathematical crown of the "pearl" can not be expected. Title Description DescriptionNow please compile a program to verify Goldbach conjecture.
First, an odd n is given, which requires the output of 3 prime numbers, and the sum of the 3 prime numbers equals the odd number of inputs. input/output format input/output Input Format:
There is only one row, containing a positive odd number n, where 9<n<20000
output Format:
Only one row, output 3 prime numbers, the sum of the 3 prime numbers equals the odd number of inputs. The adjacent two prime numbers are separated by a space, and there is no space behind the last prime number. If the presentation method is not unique, output the least-number scheme, and if the first-smallest scheme is not unique, output a scheme with the smallest second number. input and Output sample sample Input/output sample Test point # # Input Sample: the Sample output: 3 3 2003 ideas: First from small to large, looking for the first prime, found, from this prime number to find a second prime, if found, the direct output can (the third number is n-i-j) The code is as follows:
1#include <stdio.h>2#include <math.h>3 intpriintA//Judging Prime numbers4 {    5      for(intI=2; I<=sqrt (a); i++)6     {7         if(a%i==0)return 1;//found, return 18     }    9     return 0;//otherwise returns 0Ten }     One intMain () A {     -     intN,a,b,c;  -scanf"%d",&N);  the      for(intI=2; i<n;i++)//Find the first number -     {     -         if(PRI (i) = =0)  -          for(intj=2; j<n-i;j++)//determines whether the first number is prime, and if so, the second number +         {     -             if(PRI (j) = =0&&pri (n-i-j) = =0)//Find 2 numbers naturally determines the third number, and judges the second and third numbers as prime numbers +             { Aprintf"%d%d%d\n", i,j,n-i-j); at                 return 0; -             }     -         }     -     }     -}

Rokua-Goldbach conjecture (upgraded version)-boss War-Getting started comprehensive Exercise 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.