| | |
finding prime numbers that add up to even number?
![]() |
•
•
Join Date: Apr 2008
Posts: 2
Reputation:
Solved Threads: 0
Goldbach's conjecture in mathematics is that every even integer number greater than 2 can be expressed as the sum of two prime numbers. Write a program that prompts the user for a number, checks that it is positive and even, and prints the two primes that sum to it.
First I have a question: Is there a mistake? Maybe an even number adds up to 3 primes summed up or even more?
Then... Here's how far I've gotten:
I've been stuck here for a while now...
Any hints would be appreciated!
Thank you in advance!
First I have a question: Is there a mistake? Maybe an even number adds up to 3 primes summed up or even more?
Then... Here's how far I've gotten:
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <math.h> int even (int number); int prime (int number); int main () { int number, sum=0, divisor; printf ("Please enter a whole number: "); scanf ("%d", &number); if (number>=1) { prime (number); } return (0); } int even (int number) { return (!(number%2)); } int prime (int number) { if (even (number)) {
Any hints would be appreciated!
Thank you in advance!
Last edited by Narue; Apr 9th, 2008 at 10:37 am. Reason: Added code tags, do it yourself nex time.
Start by working out a way of enumerating the prime numbers. If you don't know what the prime numbers below your entered number are, you can't solve the problem. Personally, I would probably create an array of primes to save myself the trouble of calculating them. However, you might want to calculate them, which reduces the current problem from "find two primes that add up to N" to "list all of the primes from 0 to N". That's a much more common problem that you can do research on.
Once you have the primes, it's not terribly difficult to walk over them, take the sum, and compare it with N.
Once you have the primes, it's not terribly difficult to walk over them, take the sum, and compare it with N.
I'm here to prove you wrong.
•
•
•
•
First I have a question: Is there a mistake? Maybe an even number adds up to 3 primes summed up or even more?
an even number can only be the sum of three primes, if one of those primes is the number 2. which isn't saying anything that the Conjecture isn't already saying. because if you subtract 2 from each side of the equation, you have the original conjecture: "even numbers greater than 2 can be expressed as the sum of two prime numbers"
and i suppose an even number (greater than 6) can be expressed by the sum of four primes because every even number greater than 6 can be expressed as the sum of two even numbers greater than 2.
which brings us back full circle, back to Mr. Goldbach.
the point is that (as far as anyone has ever calculated) ALL even numbers >2 are the sum of two prime numbers.
4 = 2 + 2
6 = 3 + 3
8 = 5 + 3
10 = 5 + 5 or 7 + 3
12 = 5 + 7
14 = 7 + 7 or 11 + 3
16 = 11 + 5 or 13 + 3
18 = 13 + 5 or 11 + 7
20 = 13 + 7
22 = 17 + 5 or 11 + 11
24 = 17 + 7 or 13 + 11
26 = 19 + 7 or 13 + 13
28 = 23 + 5 or 17 + 11
30 = 23 + 7 or 17 + 13
32 = 29 + 3 or 19 + 13
34 = 17 + 17 or 29 + 5 or 31 + 3
36 = 19 + 17 or 29 + 7
38 = 19 + 19 or 31 + 7
40 = 23 + 17 or 29 + 11 or 37 + 3
etc.
I prolly missed a few. but you get the idear.
FYI, here's a tidy list of the first 1000 prime numbers:
http://primes.utm.edu/lists/small/1000.txt
.
Last edited by jephthah; Apr 9th, 2008 at 5:45 pm.
![]() |
Other Threads in the C Forum
- Previous Thread: Pigeonhole Sort Help
- Next Thread: Grabbing and reading text file
| Thread Tools | Search this Thread |
* adobe ansi api array asterisks binarysearch calculate centimeter char character cm convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile createprocess() csyntax directory feet fflush fgets file floatingpointvalidation fork frequency function getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling gtkwinlinux hacking highest homework i/o inches infiniteloop interest intmain() kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives match meter microsoft mqqueue mysql number oddnumber odf open opendocumentformat openwebfoundation owf pattern pdf performance posix power probleminc program programming pyramidusingturboccodes read recv recvblocked repetition scanf scheduling segmentationfault send single socketprograming socketprogramming stack standard strchr string suggestions systemcall unix urboc user variable voidmain() wab whythiscodecausesegmentationfault win32api windows.h






