Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Project Euler Problem 10
//Rextester.Program.Main is the entry point for your code. Don't change it //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; namespace Rextester { public class Program { static long max_n = 2000000; static List<long> primes = new List<long>(); public static void Main(string[] args) { long n = 2, sum_of_primes = 0; primes.Add(n); sum_of_primes += n; n++; do { if (IsPrime (n)) { primes.Add(n); sum_of_primes += n; } n += 2; } while (n < max_n); Console.WriteLine("The solution is: " + sum_of_primes); } public static bool IsPrime(long n) { // Console.WriteLine("Testing: " + n); foreach (long prime in primes) { if (prime * prime > n) { break; } else if (n % prime == 0) { return false; } } return true; } } }
run
|
edit
|
history
|
help
0
Swap 2
Is String a Palindrome
Fixing Broken Lines with Regex
30272 Example1
6.4 Parallelism: threads and events
a
Const
TEst1
Unsorted array with most occurence
puzzle piezas