Пример #1
0
        public static massiveinteger operator *(massiveinteger m1, massiveinteger m2)
        {
            var total   = new massiveinteger();
            var current = m1.digits.ToList();

            foreach (var digit in m2.digits)
            {
                var currentval = new massiveinteger(current.ToArray());
                for (int i = 0; i < digit; i++)
                {
                    total += currentval;
                }
                current.Insert(0, 0);
            }
            return(total);
        }
Пример #2
0
        private static void process_mnpq(mnpq item)
        {
            abcd baseAbcd = item.get_abcd();

            if (new[] { baseAbcd.a, baseAbcd.b, baseAbcd.c /*NOT d (although doesn't seem to make much difference in C++*/ }.gcd() == 1)
            {
                HashSet <cube> thisCubes = new HashSet <cube>();

                vectortriple baseTriple = get_triple(baseAbcd, item);
                long         sumgcd     = baseTriple.u.gcd() + baseTriple.v.gcd() + baseTriple.n.gcd();
                long         l          = baseTriple.u.length;
                var          abcds      = baseAbcd.get_permutations();
                foreach (var abcd in abcds)
                {
                    var triple = get_triple(abcd, item);
                    for (int f = 0; f < 8; f++)
                    {
                        bool flipX   = (f & 1) != 0,
                             flipY   = (f & 2) != 0,
                             flipZ   = (f & 4) != 0;
                        int [] order = { 0, 1, 2 };
                        foreach (var orderPermutation in Permutations.Of(order, 3, false, false))
                        {
                            var cube = new cube(triple.u, triple.v, triple.n, flipX, flipY, flipZ, orderPermutation);
                            thisCubes.Add(cube);
                        }
                    }
                }

                massiveinteger thisS = new massiveinteger();
                foreach (var thisCube in thisCubes)
                {
                    if (!thisCube.is_oversize() && cubesDone.Add(thisCube))
                    {
                        long maxSize = new[] { thisCube.width, thisCube.height, thisCube.depth }.Max();
                        long tmax = N / maxSize;
                        if (tmax * maxSize > N)
                        {
                            throw new InvalidOperationException("tmax is too lenient - would produce oversize cubes!");
                        }
                        if ((tmax + 1) * maxSize <= N)
                        {
                            throw new InvalidOperationException("tmax is not lenient enough - could squeeze another one out!");
                        }
                        if (tmax <= 0)
                        {
                            throw new InvalidOperationException("tmax <= 0");
                        }

                        for (long t = 1; t <= tmax; t++)
                        {
                            long repeatability = (N + 1L - thisCube.width * t) *
                                                 (N + 1L - thisCube.height * t) *
                                                 (N + 1L - thisCube.depth * t);
                            if (repeatability <= 0)
                            {
                                throw new InvalidOperationException("Repeatability <= 0");
                            }
                            massiveinteger ehp = new massiveinteger(l * l * l) * new massiveinteger(t * t * t) +
                                                 new massiveinteger(l * sumgcd) * new massiveinteger(t * t) + new massiveinteger(sumgcd * t + 1);
                            massiveinteger contributionS = ehp * new massiveinteger(repeatability);
//                            var line = $"{item},{t},{thisS},{contributionS},";
                            thisS += contributionS;
//                            line += thisS;
//                            File.AppendAllLines("s5_verbose_csh.csv", new [] {line});
                        }
                    }
                }
                S += thisS;
                S.truncate(9);
            }
        }