예제 #1
0
        static void Main(string[] args)
        {
            const int limit  = 1000000;
            var       primes = new HashSet <int>();

            for (mpz_t p = 2; p <= limit; p = p.NextPrimeGMP())
            {
                primes.Add((int)p);
            }
            var indexes   = Enumerable.Range(0, primes.Count + 1).ToArray();
            int max       = 0;
            int bestprime = 0;

            for (int i = 0; i < primes.Count &&
                 primes.Skip(i).Take(max).Sum() <= limit /* is it possible to generate a longer string? */
                 ; i++)
            {
                for (int c = max; c <= primes.Count - i; c++)
                {
                    var sum = primes.Skip(i).Take(c).Sum();
                    if (sum >= limit)
                    {
                        break;
                    }
                    if (c > max && primes.Contains(sum))
                    {
                        bestprime = sum;
                        max       = c;
                    }
                }
            }
            Console.WriteLine($"\n{bestprime}, max = {max}");
        }
예제 #2
0
        static mpz_t S(mpz_t n)
        {
            mpz_t result = new mpz_t(0);

            for (mpz_t p = 2; p <= n; p = p.NextPrimeGMP())
            {
            }
            return(result);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var tot = new mpz_t(0);

            for (mpz_t p = 2; p < 2e6; p = p.NextPrimeGMP())
            {
                tot += p;
            }
            Console.WriteLine(tot);
        }
예제 #4
0
        static void Main(string[] args)
        {
            var p = new mpz_t(2);

            for (int i = 1; i < 10001; i++)
            {
                p = p.NextPrimeGMP();
            }
            Console.WriteLine(p);
        }
예제 #5
0
        static void MakePrimes()
        {
            var primesList = new List <mpz_t>();

            for (mpz_t p = 2; p <= rbmax; p = p.NextPrimeGMP())
            {
                primesList.Add(p);
            }
            Primes = primesList.ToArray();
        }
예제 #6
0
 static int smpf(mpz_t n)
 {
     for (mpz_t p = 2; ; p = p.NextPrimeGMP())
     {
         if (n % p == 0)
         {
             return((int)p);
         }
     }
 }
예제 #7
0
        static void Main(string[] args)
        {
            int count = 0;
            var sw    = Stopwatch.StartNew();

            for (mpz_t p = 2; p < 1e6; p = p.NextPrimeGMP())
            {
                if (IsCircular(p))
                {
                    count++;
                }
            }
            sw.Stop();
            Console.WriteLine($"{count}, in {sw.Elapsed}");
        }
예제 #8
0
        static Program()
        {
            fib[1] = 1;
            for (int i = 2; i <= N; i++)
            {
                fib[i] = fib[i - 1] + fib[i - 2];
            }
            var primesList = new List <mpz_t>();

            for (mpz_t p = 2; p <= fib.Last(); p = p.NextPrimeGMP())
            {
                primesList.Add(p);
            }
            primes   = primesList.Select(i => (int)i).ToArray(); //it should fit
            products = Enumerable.Repeat(0, fib.Last() + 1).Select(i => new mpz_t(i)).ToArray();
        }
예제 #9
0
        static void Main(string[] args)
        {
            mpz_t sum = 0, p = 7;
            int   found = 0;

            while (found < 11)
            {
                do
                {
                    p = p.NextPrimeGMP();
                } while (!IsTruncatable(p));
                Console.WriteLine(p);
                sum += p;
                found++;
            }
            Console.WriteLine($"Sum = {sum}");
        }
예제 #10
0
        static void Main(string[] args)
        {
            var primes = new List <mpz_t>();
            int c      = 0;

            for (mpz_t p = 2; ++c < 1e6; p = p.NextPrimeGMP())
            {
                primes.Add(p);
            }
            mpz_t limit = 1e12;

            Console.WriteLine("Made primes");
            var squbes = new SortedSet <mpz_t>();

            for (int i = 0; i < primes.Count; i++)
            {
                if (i % 1000 == 0)
                {
                    Console.WriteLine(i);
                }
                for (int j = 0; j < primes.Count; j++)
                {
                    if (i != j)
                    {
                        var sqube = primes[i].Power(2).Multiply(primes[j].Power(3));
                        if (sqube > limit)
                        {
                            break;
                        }
                        //if (sqube.ToString().Contains("200") && IsPrimeProof(sqube))
                        //{
                        squbes.Add(sqube);
                        //}
                    }
                }
            }

            var pp200squbes = squbes.Where(sq => IsPrimeProof(sq) && sq.ToString().Contains("200"))
                              .OrderBy(s => s).ToArray();

            var result = pp200squbes[199];

            Console.WriteLine(result);
        }
예제 #11
0
        static void Main(string[] args)
        {
            const int limit = 2500000;

            mpz_t prime      = 2;
            int   totalCount = 0;
            var   peaks      = new Dictionary <int, Pos>()
            {
                [0] = new Pos(0, 0, 0),
                [1] = new Pos(2, 2, 1)
            };
            Stopwatch sw = Stopwatch.StartNew();

            for (int i = 2; i <= limit; i++)
            {
                if (i % 10000 == 0)
                {
                    var velocity = (1000000000d) / sw.ElapsedTicks;
                    Console.Write($"{(double)i / limit:P1}, velocity={velocity:0.00000}\r");
                    sw.Restart();
                }
                var next2Primes = (prime = prime.NextPrimeGMP(), prime = prime.NextPrimeGMP());
                var xpos        = peaks[i - 1].X + next2Primes.Item1 + next2Primes.Item2;
                var ypos        = peaks[i - 1].Y - next2Primes.Item1 + next2Primes.Item2;
                peaks[i] = new Pos(xpos, ypos, i);
            }
            Console.WriteLine("\nMade peaks");

            int lowerLimit = 1;

            peaks[2].IsHull = true;
            for (int i = 2; ; i++)
            {
                Console.WriteLine($"{lowerLimit} - {i}, {(double)i / limit:P1}");
                int      count    = 1;
                Fraction minAngle = Fraction.AngleBetween(peaks[i], peaks[i - 1]);
                for (int j = i - 2; j >= lowerLimit; j--)
                {
                    var angle = Fraction.AngleBetween(peaks[i], peaks[j]);
                    if (angle.CompareTo(minAngle) < 0)
                    {
                        minAngle = angle;
                        count++;
                    }
                }
                totalCount += count;
                if (i == limit)
                {
                    break;
                }
                if (peaks[i].IsHull)
                {
                    var next = peaks.Where(p => p.Key > i)
                               .OrderByDescending(p => Fraction.AngleBetween(p.Value, peaks[i]))
                               .First();
                    next.Value.IsHull = true;
                    lowerLimit        = i;
                }
            }

            Console.WriteLine($"\n{totalCount}");
        }