Euler serisinin onuncu yazısında, Project Euler’in 10. sorusunu çözeceğiz;
Orjinal Soru; The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17 Find the sum of all the primes below two million
Türkçesi; 10'dan küçük asal sayıların toplamı 17'dir; 2 + 3 + 5 + 7 = 17 2.000.000'dan küçük tüm asal sayıların toplamını bulun
Önce siz çözmeyi deneyin, çözemezseniz;
private static List<int> Euler10()
{
    int counter = 3;
    bool isPrime;
    int j;
    List<int> primes = new List<int>();
    primes.Add(2);
    while (counter < = 2000000)
    {
        j = 0;
        isPrime = true;
        while (primes[j] * primes[j] <= counter)
        {
            if (counter % primes[j] == 0)
            {
                isPrime = false;
                break;
            }
            j++;
        }
        if (isPrime)
        {
            primes.Add(counter);
        }
        counter += 2;
    }
    return primes;
}
public static class Program
{
    public static void Main(string[] args)
    {
        var Sonuc = Euler10();
        Console.WriteLine("Euler 10 sonuç : " + Sonuc.Sum())
        Console.ReadLine();
    }
}Senior Software Engineer, @Microsoft
Ada ve Ege'nin babası ;)
Makale Adedi: 484