Function to generate all primes
static List < int > SieveOfEratosthenes ( int n ) { bool [ ] prime = new bool [ 2 * n + 1 ] ; Array . Fill ( prime , true ) ; for ( int p = 2 ; p * p <= 2 * n ; p ++ ) {