Ejemplo n.º 1
0
        public long s(long n)
        {
            if (n < 1)
            {
                return(0);
            }
            else if (n == 1)
            {
                return(1);
            }

            List <int> pPowers = PrimeTools.PrimeFactorizationPowers(n);
            long       count   = 1;

            foreach (int power in pPowers)
            {
                if (power >= 3)
                {
                    count *= (power - 1);
                }
            }

            return(count);

            //throw new NotImplementedException($"Count cube-full divisors of {n}.");
        }
Ejemplo n.º 2
0
        public void PrimesLessThan_VariousInputs_ChecksThem(
            [ValueSource("PrimesLessThanTestValues")] PrimesLessThanTestValue PrimesLessThanTestValue)
        {
            var result   = PrimeTools.PrimesLessThan(PrimesLessThanTestValue.Number);
            var expected = PrimesLessThanTestValue.Expected;

            CollectionAssert.AreEqual(expected, result);
        }
Ejemplo n.º 3
0
        public void PrimeTools_TestSieve()
        {
            // Arrange
            ulong[]    expected   = new ulong[] { 2, 3, 5, 7, 11 };
            PrimeTools primeTools = new PrimeTools();

            // Act
            var actual = primeTools.Sieve(13);

            // Assert
            actual.ShouldAllBeEquivalentTo(expected);
        }
Ejemplo n.º 4
0
        public int[] BPrimeFactorization(int n)
        {
            int[]       powers = new int[n + 1];
            List <long> pieceFactorization;

            for (int i = n; i >= 2; i--)
            {
                int power = 2 * i - n - 1;
                pieceFactorization = PrimeTools.PrimeFactorization(i);
                foreach (long factor in pieceFactorization)
                {
                    powers[factor] += power;
                }
            }
            return(powers);
        }
Ejemplo n.º 5
0
        public bool cubeFull(long n)
        {
            if (n < 1)
            {
                return(false);
            }
            else if (n == 1)
            {
                return(true);
            }

            List <long> pF = PrimeTools.PrimeFactorization(n);
            int         i  = 0;
            int         j;

            //Console.WriteLine($"Counting duplicates, {n} has {pF.Count} prime factors.");
            while (i < pF.Count)
            {
                j = i + 1;
                while (j < pF.Count && pF[i] == pF[j])
                {
                    j++;
                }

                if (j - i < 3)
                {
                    return(false);
                }
                else if (j == pF.Count)
                {
                    return(true);
                }
                else
                {
                    i = j;
                }
            }

            throw new NotImplementedException($"Determine whether {n} is cube-full.");
        }
Ejemplo n.º 6
0
        public void IsPrime_VariousInputs_ChecksThem(int number, bool expected)
        {
            var result = PrimeTools.IsPrime(number);

            Assert.AreEqual(expected, result);
        }