Wuhan University of Science and Technology acm:1009: Chinese Edition C language Programming tutorial (second Edition) example 4.18

Source: Internet
Author: User

Problem Description

Verify Goldbach conjecture that any even number of sufficiently large (>=4) can be represented by a sum of two primes.

Input

Enter an even n. (2<n<=10000)

Output

Find A, B make n=a+b

Where A and B are two primes, and a<=b.

Sample Input

4

100

Sample Output

2 2

3 97

1#include <iostream>2 3#include <math.h>4 5 using namespacestd;6 7 intPrimeintm)8 9 {Ten  One          intI,n; A  -          if(m==1)return 0; -  theN= (int) sqrt (Double) m); -  -           for(i=2; i<=n;i++) -  +                    if(m%i==0)return 0; -  +                    return 1; A  at } -  - intMain () -  - { -  in          intCount,i,number; -  toCount=0; +  -           while(cin>>Number ) the  *          { $ Panax Notoginseng                     for(i=2; i<=number/2; i=i+1) -  the                             if(Prime (i) &&prime (number-i)) +  A                             { the  +cout<<i<<" "<<number-i<<Endl; -  $                                       Break; $  -                             } -  the          } - Wuyi          return 1; the  -}

Other code:

1#include <stdio.h>2#include <math.h>3 intPrime (intm)4 {5     intr = m/2;6      for(inti =2; I <= R; i++)7         if(m% i = =0)8             return 0;9     return 1;Ten } One intMain () A { -     intn,i; -      while(~SCANF ("%d",&N)) the     { -          for(i=2; i<=n/2; i++) -             if(Prime (i) &&prime (ni)) { -printf"%d%d\n", i,n-i); +                  Break; -             } +     } A     return 0; at}

Wuhan University of Science and Technology acm:1009: Chinese Edition C language Programming tutorial (second Edition) example 4.18

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.