Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Pinterest
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

Goldbach’s Conjecture

Goldbach’s con­jec­ture — Every even inte­ger greater than 2 can be rep­re­sented as the sum of two primes numbers.

Exam­ple:

Given Num­ber : 200

Prime Numbers are 3 197
Prime Numbers are 7 193
Prime Numbers are 19 181
Prime Numbers are 37 163
Prime Numbers are 43 157
Prime Numbers are 61 139
Prime Numbers are 73 127
Prime Numbers are 97 103

Approach:

  • Check if num­ber if not even, return.
  • Check if num­ber is less than 2, return.
  • Nav­i­gate i, from 3 to num­ber check if i and (x-i) is prime, if yes, Print it

Code:

Output :
Prime Numbers are 3 97
Prime Numbers are 11 89
Prime Numbers are 17 83
Prime Numbers are 29 71
Prime Numbers are 41 59
Prime Numbers are 47 53

You may also like...

  • Mav­er­ick

    Nice Approach! But can this be improved using mem­o­iza­tion (DP)?