Run Code
|
API
|
Code Wall
|
Users
|
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
Please
log in
to post a comment.
Dependencia de datos
abebe
Finding a Substring in a Main String
Learning Rounding and Truncation from the Maths library
Display the pattern like diamond by using c# for loop
Inheritance Ctor
a1
Hello world test
Gamez
IntToExcelColumnNotation
Please log in to post a comment.