Пример #1
0
            public static void Run(Input input, Output output)
            {
                var primes = PrimesCalculator.CalculatePrimesErathospen(10000000);

                var t = Int32.Parse(input.ReadLine());

                for (int t1 = 0; t1 < t; t1++)
                {
                    var n = Int32.Parse(input.ReadLine());
                    {
                        int i = 1;
                        while (true)
                        {
                            int component1 = 1;
                            int component2 = 1;
                            if (i % 2 == 0)
                            {
                                component1 = i / 2;
                                component2 = i + 1;
                            }
                            else
                            {
                                component1 = i;
                                component2 = (i + 1) / 2;
                            }

                            var component1PrimeDividors = GetPrimeDividors(component1, primes);
                            var component2PrimeDividors = GetPrimeDividors(component2, primes);
                            foreach (var k in component2PrimeDividors.Keys)
                            {
                                if (!component1PrimeDividors.ContainsKey(k))
                                {
                                    component1PrimeDividors.Add(k, 0);
                                }
                                component1PrimeDividors[k] += component2PrimeDividors[k];
                            }
                            var overallDividors = 1;
                            foreach (var k in component1PrimeDividors.Keys)
                            {
                                overallDividors *= component1PrimeDividors[k] + 1;
                            }
                            if (overallDividors > n)
                            {
                                output.WriteLine(((long)component1 * (long)component2).ToString());
                                break;
                            }
                            i++;
                        }
                    }
                }
            }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Calculating primes...");

            int first = 3, last = 100;

            if (args.Length > 1)
            {
                int.TryParse(args[0], out first);
                int.TryParse(args[1], out last);
            }

            var calc = new PrimesCalculator();

            foreach (int n in calc.Calculate(first, last))
            {
                if (Console.KeyAvailable && Console.ReadKey().Key == ConsoleKey.Q)
                {
                    break;
                }
                Console.WriteLine(n);
            }
        }