Example #1
0
            public static void Run(Input input, Output output)
            {
                var meta = input.ReadLine().Split(' ');
                var N    = int.Parse(meta[0]);
                var K    = int.Parse(meta[1]);

                var pu             = new PrimesUtils(1000000);
                var allPrimes      = pu.GetSievePrimes();
                var primesToTest   = new List <int>();
                var currPrimeIndex = 0;
                var excl           = new HashSet <int>()
                {
                    2, 5
                };

                while (allPrimes[currPrimeIndex] < N)
                {
                    if (!excl.Contains(allPrimes[currPrimeIndex]))
                    {
                        primesToTest.Add(allPrimes[currPrimeIndex]);
                    }
                    currPrimeIndex++;
                }

                var sums = GetConcatenateablePrimesSetsSums(primesToTest, K, pu);

                sums.Sort();
                for (int i = 0; i < sums.Count; i++)
                {
                    output.WriteLine(sums[i].ToString());
                }
            }
Example #2
0
 public void PrimesUtilsShouldGetAllPrimes()
 {
     #region Arrange
     var pu = new PrimesUtils(1000000);
     #endregion
     #region Act
     var primes = pu.GetSievePrimes();
     #endregion
     #region Assert
     Assert.AreEqual(78498, primes.Count);
     Assert.AreEqual(2, primes[0]);
     Assert.AreEqual(999983, primes[78497]);
     #endregion
 }