/*------------------------------------------------------------------------
Author: AaronBai
Project: outputs prime numbers within a specified range and verifies the gedebach conjecture within a certain range.
State:
Creation Date: 2006-10-24
Description:
------------------------------------------------------------------------*/
# Include <stdio. h>
# Define M 10001 // define the verification scope
// Function CreatPrimeList (): EPO number table
Void CreatPrimeList (int PrimeList [])
{
Int I, j;
// Set each element of PrimeList to a positive integer starting from 0.
For (I = 0; I <M; I = I + 1)
PrimeList [I] = I;
// Remove the multiples of the identified prime numbers from the table (set them to 0)
I = 2;
While (I <M/2)
{
For (j = I + 1; j <M; j = j + 1)
If (PrimeList [j]! = 0 & PrimeList [j] % PrimeList [I] = 0)
PrimeList [j] = 0;
// Determine the position of the next Prime Number
I = I + 1;
While (PrimeList [I] = 0)
I = I + 1;
}
}
// Function NextPrimeNumber (): returns the next prime number.
Int NextPrimeNumber (int p, int PrimeList [])
{
P = p + 1;
While (PrimeList [p] = 0)
P = p + 1;
Return PrimeList [p];
}
// Gedebach conjecture verification: The godebach conjecture is verified in the range from 4 to M.
Void prove (int PrimeList [])
{
Int x, p;
// Verify the godebach conjecture for all the even numbers from 4 to M
X = 4;
While (x <M)
{
// Check whether the remaining part after an even number is subtracted from a prime number is still a prime number.
P = PrimeList [2];
While (p <= x/2 & PrimeList [x-p] = 0)
P = NextPrimeNumber (p, PrimeList );
// Output the check result
If (p> x/2) // finds an even number that cannot be decomposed into two prime numbers and
Printf ("great discovery: it's wrong to guess it! /N ");
Else // PrimeList [x-p]! = 0. decomposition successful
Printf ("% d = % d + % d/n", x, p, x-p );
// Check the next even number
X = x + 2;
}
// Return 0;
}
// Main function: outputs prime numbers within a specified range and verifies the gedebach conjecture within a certain range.
Int main ()
{
Int PrimeList [M]; // indicates the array that stores the prime number table.
Int I;
// Create a prime number table
CreatPrimeList (PrimeList );
// Print all prime numbers in the M range
Printf ("print out all prime numbers in M/n ");
For (I = 2; I <M; I ++)
{If (PrimeList [I]! = 0)
Printf ("% d/n", PrimeList [I]);
}
// Gedebach conjecture verification: The godebach conjecture is verified in the range from 4 to M.
Printf ("verifying godebach conjecture/n in the range from 4 to M ");
Prove (PrimeList );
}