Example #1
0
        private long GetSquereFreeBinomilaNumber(int number, int row, Utils.Prime primes)
        {
            var decomposition = new Dictionary<long, long>();

            for (var r = 1; r <= row; r++)
            {
                var numberDecomposition = primes.GetDecomposition(r);

                foreach (var n in numberDecomposition)
                {
                    if (!decomposition.ContainsKey(n.Key))
                    {
                        decomposition.Add(n.Key, 0);
                    }

                    decomposition[n.Key] += n.Value;
                }
            }

            for (var n = 1; n <= number; n++)
            {
                var numberDecomposition = primes.GetDecomposition(n);
                foreach (var d in numberDecomposition)
                {
                    decomposition[d.Key] -= d.Value;
                }
            }

            for (var n = 1; n <= row - number; n++)
            {
                var numberDecomposition = primes.GetDecomposition(n);
                foreach (var d in numberDecomposition)
                {
                    decomposition[d.Key] -= d.Value;
                }
            }

            if (decomposition.Any(t => t.Value > 1))
            {
                return 0;
            }

            return decomposition.Aggregate(1L, (current, d) => current * (long)Math.Pow(d.Key, d.Value));
        }