Ejemplo n.º 1
0
        static ulong Calculate(ulong n)
        {
            PrimeCalculator calculator = new PrimeCalculator();
            var primes = calculator.GetAllPrimes_Atkin(n);
            ulong maxPrime = primes[primes.Count - 1];
            ulong sum = 0;

            for (int i = 0; i < primes.Count - 2; i++)
            {
                if (i%10000==0)
                    Console.WriteLine(i);

                var a = primes[i];
                var factors = (ulong)calculator.Factor(a + 1).Distinct().Prod();

                if (factors > 10)
                {
                    sum += CalculateByFactor(a, factors, maxPrime, primes);
                }
                else
                {
                    sum += CalculateByPrimes(i, primes, a, maxPrime);

                }
            }
            return sum;
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Stopwatch sw = new Stopwatch();
            PrimeCalculator calc = new PrimeCalculator();
            var allprimes = calc.GetAllPrimes_Atkin(100000000);
            List<ulong> primes = new List<ulong>();
            foreach (var prime in allprimes)
            {
                var tmp = prime;
                bool[] digits = new bool[10];
                bool notok = false;
                while (tmp > 0)
                {
                    var digit = tmp % 10;
                    if (digit == 0 || digits[digit])
                    {
                        notok = true;
                        break;
                    }
                    digits[digit] = true;
                    tmp /= 10;
                }
                if (!notok)
                    primes.Add(prime);
            }
            FindSetsRecursive(primes, new List<ulong>(), new bool[10], 0, 0);

            Console.WriteLine(result);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            ulong result = 0;
            ulong N = (ulong)1e6;
            PrimeCalculator calc = new PrimeCalculator();
            var primes = calc.GetAllPrimes_Atkin((ulong)N);
            foreach (var prime in primes)
            {
                if (prime < 5)
                    continue;

                ulong fact = 1;
                ulong sum = 0;
                for (ulong k = 2; k <= prime - 5; k++)
                    fact = (fact * k) % prime;
                sum = (sum+fact) % prime;
                fact = (fact * (prime - 4) % prime);
                sum = (sum + fact) % prime;
                fact = (fact * (prime - 3) % prime);
                sum = (sum + fact) % prime;
                fact = (fact * (prime - 2) % prime);
                sum = (sum + fact) % prime;
                fact = (fact * (prime - 1) % prime);
                sum = (sum + fact) % prime;

                result = checked(result + sum % prime);

            }

            Console.WriteLine(result);
        }
Ejemplo n.º 4
0
 static void Main(string[] args)
 {
     PrimeCalculator calculator = new PrimeCalculator();
     ulong limit = 100000000;
     Stopwatch sw = Stopwatch.StartNew();
     var primes = calculator.GetAllPrimes_Atkin(limit / 2);
     Calculate(calculator, primes, new List<ulong>() {2}, 1, 2, limit );
     Console.WriteLine(sw.ElapsedMilliseconds/1000);
     Console.WriteLine(sum +1); // 1 is not calculated
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            ulong MAX = (ulong)1e14;
            ulong result = 0;
            PrimeCalculator calc = new PrimeCalculator();
            calc.GetAllPrimes_Atkin((ulong)Math.Sqrt(MAX));

            Stack<ulong> candidates = new Stack<ulong>();

            for (ulong i = 1; i < 10; i++)
            {
                candidates.Push(i);
            }

            while (candidates.Count > 0)
            {
                var num = candidates.Pop();
                var sumDigits = SumDigits(num);
                if (num % sumDigits > 0)
                    continue;

                bool isStrong = calc.IsPrime(num / sumDigits);
                if (isStrong)
                {
                    for (ulong i = 0; i < 10; i++)
                    {
                        var tmp = AddDigit(num, i);
                        if (tmp>MAX)
                            break;
                        if (calc.IsPrime(tmp))
                            result += tmp;
                    }
                }
                for (ulong i = 0; i < 10; i++)
                {
                    var tmp = AddDigit(num, i);
                    if (tmp > MAX)
                        break;

                    candidates.Push(tmp);
                }

            }

            Console.WriteLine(result);
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Calculate();
            return;

            PrimeCalculator calc = new PrimeCalculator();
            calc.GetAllPrimes_Atkin((ulong)5e8);

            ulong inc = 2 * 2 * 2*3 * 3 * 5 * 7 * 11 * 13 * 17 * 19;
            ulong n = inc;
            Console.WriteLine(inc);

            ulong max = 0;

            for (;;)
            {

                //for (ulong x = n+1; x <= 2*n ; x+=1)
                //{

                //    if ((n * x) % (x - n) == 0)
                //    {
                //        count++;
                //    }
                //}

                var count = (NumOfDivisorSquare(n, calc) + 1) / 2;
                if (count > max)
                {
                    Console.WriteLine("{0} {1}", n, count);
                    max = count;
                }
                if (count >= 4000000)
                {
                    Console.WriteLine(n);
                    return;
                }
                //Console.WriteLine(count);
                n+=inc;
            }
        }
Ejemplo n.º 7
0
        static void Calculate()
        {
            PrimeCalculator calc = new PrimeCalculator();
            var primes = calc.GetAllPrimes_Atkin((ulong)100);

            ulong firstGuess = 1;
            ulong divNum = 1;
            int count = 0;
            while (divNum < N*2+1)
            {
                firstGuess *= primes[count];
                divNum *= 3;
                count ++;
            }

            MinFound = firstGuess;
            Console.WriteLine(firstGuess);
            Console.WriteLine(count);
            Calculate(calc, primes, new List<ulong>(){2}, 0, 2, N);
            //Console.WriteLine(MinFound);
        }
Ejemplo n.º 8
0
 static void Main(string[] args)
 {
     PrimeCalculator calc = new PrimeCalculator();
     Console.WriteLine(calc.GetAllPrimes_Atkin(2000000).Sum(x=>(decimal)x));
 }