Output prime numbers within the specified range and verify the gedebach conjecture within a certain range

Source: Internet
Author: User
/*------------------------------------------------------------------------

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 );

}

 
 

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.