Difference between revisions of "Talk:Prime number"
| Line 31: | Line 31: | ||
[[User:Ga ohoyt|Ga ohoyt]] 13:32, 10 January 2008 (EST) | [[User:Ga ohoyt|Ga ohoyt]] 13:32, 10 January 2008 (EST) | ||
| + | |||
| + | == Flaw in proof == | ||
| + | |||
| + | "It is easy to prove that there are an infinite number of primes using Euclid's second theorem. If there were a finite number of primes, you could multiply them all together and add 1. The resulting number would show the existence of a new prime, since it would not be divisible by any smaller prime (it would always have a remainder of 1)." This argument doesn't work. 510511 = 2 * 3 * 5 * 7 * 11 * 13 * 17 + 1, but it's not prime. [[User:Sepura|Sepura]] 13:21, 20 February 2008 (EST) | ||
Revision as of 18:21, February 20, 2008
Primality testing - Problems with the number 4
When testing whether a number N is divisible by s, using values of s from 2 to N - 1, when N is 4, the method correctly determines that 4 is not prime, because it is divisible by 2. This example is in the C programming language.
for (s = 2; s < N - 1; ++s) {
if (N % s == 0) {
printf("N is not a prime number.");
}
}
However, when using values of m from 2 to the square root of n, when n is 4, an error can occur. Since 2 is the square root of 4, the test range is 2 to 2, and, if the range is exclusive, as in a for-loop, the whole test is skipped, and 4 is incorrectly determined to be a prime number.
for (s = 2; s < sqrt(N); ++s) {
if (N % s == 0) {
printf("N is not a prime number.");
}
}
Isaac4given 11:28, 10 January 2008 (EST)
I'm surprised that 9 worked. Try.
for (s = 2; s <= sqrt(N); ++s) { // less than or equal to catch perfect squares
if (N % s == 0) {
printf("N is not a prime number.");
}
}
Ga ohoyt 13:32, 10 January 2008 (EST)
Flaw in proof
"It is easy to prove that there are an infinite number of primes using Euclid's second theorem. If there were a finite number of primes, you could multiply them all together and add 1. The resulting number would show the existence of a new prime, since it would not be divisible by any smaller prime (it would always have a remainder of 1)." This argument doesn't work. 510511 = 2 * 3 * 5 * 7 * 11 * 13 * 17 + 1, but it's not prime. Sepura 13:21, 20 February 2008 (EST)