Пример #1
0
        public override void Solve(IOManager io)
        {
            var n = io.ReadLong();

            foreach (var div in Divisiors.GetDivisiors(n))
            {
                io.WriteLine(div);
            }
        }
Пример #2
0
        public override void Solve(IOManager io)
        {
            var n = io.ReadInt();

            long totalLength = 0;
            var  sticks      = new int[n];
            var  maxLength   = 2 * n - 1;

            for (int i = 0; i < sticks.Length; i++)
            {
                sticks[i]    = 2 * i + 1;
                totalLength += sticks[i];
            }

            var rbtree = new RedBlackTree <Stick>();

            if (n % 2 == 0 && n >= 4)
            {
                io.WriteLine(n / 2);

                var left  = 0;
                var right = n - 1;

                for (int i = 0; i < n / 2; i++)
                {
                    io.WriteLine($"2 {sticks[left++]} {sticks[right--]}");
                }
                return;
            }

            foreach (var div in Divisiors.GetDivisiors(totalLength))
            {
                var eachLength = totalLength / div;

                if (div == 1 || eachLength < maxLength || sticks.Length % div != 0)
                {
                    continue;
                }

                var groupCount = sticks.Length / div;
                var lengths    = new long[div];
                var shift      = 0;
                var results    = Enumerable.Repeat(0, (int)div).Select(_ => new List <int>()).ToArray();

                for (int group = 0; group < groupCount; group++)
                {
                    for (int i = 0; i < lengths.Length; i++)
                    {
                        var next  = sticks[group * lengths.Length + i];
                        var index = (i + shift) % lengths.Length;
                        lengths[index] += next;
                        results[index].Add(next);
                    }

                    shift++;
                }

                if (lengths.All(l => l == lengths[0]))
                {
                    io.WriteLine(results.Length);

                    for (int i = 0; i < results.Length; i++)
                    {
                        var line = new int[results[i].Count + 1];
                        line[0] = results[i].Count;
                        results[i].CopyTo(line, 1);
                        io.WriteLine(line, ' ');
                    }

                    return;
                }
            }

            io.WriteLine("impossible");
        }