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
saxasd
Unary example
Quadratic equation
HourCouter
Sort A List of Ages of Students (Solution: Stack / O(N^3) Complexity)
Linq FirstOrDefault() null check in c#
Fórum ➡ Prime numbers implemented using LINQ statements AND using FOR loop ♦
Fortnite Generator
Decimal separator diff
ElevatorDesign_2020Dec11