Exemplo n.º 1
0
 public double ResilenceFactorFast(ulong n)
 {
     PrimeCalculator calc = new PrimeCalculator();
     var factors = calc.Factor(n).Distinct().ToList();
     ulong count = (ulong)factors.Count;
     long cancelNum = (long)n-1;
     for (ulong i = 1; i < (ulong)Math.Pow(2,count); i++)
     {
         ulong tmp = i;
         int index = 0;
         ulong bitNum = 0;
         long mul = -1;
         while (tmp > 0)
         {
             if (tmp % 2 == 1)
                 mul *= -factors[index];
             tmp /= 2;
             index++;
         }
         long numDiv = (long)(n-1) / mul;
         cancelNum -= numDiv;
     }
     var factor = (double)cancelNum / (n - 1);
     return factor;
 }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        static void CalculateRads(int n)
        {
            var primeCalculator = new PrimeCalculator();

            _rads = new int[n+1];
            _rads[1] = 1;
            for (int i = 2; i <= n; i++)
            {
                _rads[i] = primeCalculator.Factor(i).Distinct().Prod();
            }
        }
Exemplo n.º 4
0
        public int Calculate(int n, int k)
        {
            PrimeCalculator calculator = new PrimeCalculator();
            var primes = calculator.GetAllPrimes(n);
            var primeCounts = new Dictionary<int, int>();
            for (int i=n-k+1; i<=n; i++)
            {
                if (i%10000==0)
                    Console.WriteLine(i);
                var factors = calculator.Factor(i);
                foreach (int factor in factors)
                {
                    if (primeCounts.ContainsKey(factor))
                        primeCounts[factor] = primeCounts[factor] + 1;
                    else
                    {
                        primeCounts.Add(factor, 1);
                    }
                }
            }
            for (int i = 2; i <= k; i++)
            {
                var factors = calculator.Factor(i);
                foreach (int factor in factors)
                {
                    primeCounts[factor] = primeCounts[factor] - 1;
                }
            }

            int sum = 0;
            foreach (var primeCount in primeCounts)
            {
                sum += primeCount.Key * primeCount.Value;
            }
            return sum;
        }
Exemplo n.º 5
0
 static ulong NumOfDivisorSquare(ulong n, PrimeCalculator calc)
 {
     var primes = calc.Factor(n);
     return (ulong)primes.GroupBy(x => x).Select(x => x.Count()*2 + 1).Prod();
     //return Tuple.Create(primes.GroupBy(x => x).Select(x => x.Count() + 1).Prod(), primes.Count());
 }
Exemplo n.º 6
0
 static void Main(string[] args)
 {
     PrimeCalculator calculator = new PrimeCalculator();
     //Console.WriteLine(calculator.Factor(600851475143).Last().ToString());
     Console.WriteLine(calculator.Factor(600851475143).Last().ToString());
 }