Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Эйлер47
- {
- class Program
- {
- static void Main(string[] args)
- {
- var numbersAndFactors = new Dictionary<int, List<int>>();
- foreach (var e in Enumerable.Range(0, 200000))
- {
- numbersAndFactors.Add(e, GetFactors(e));
- }
- var dictAfterSelection = numbersAndFactors.Where(x => ContainsFourPrimeFactors(x.Value));
- var keysAfterSelection = dictAfterSelection.Select(x => x.Key).ToArray();
- for(int index = 0; index<keysAfterSelection.Length - 3; index++)
- {
- if ((keysAfterSelection[index] +1 == keysAfterSelection[index + 1])
- && (keysAfterSelection[index + 1] +1== keysAfterSelection[index + 2])
- && (keysAfterSelection[index + 2] +1== keysAfterSelection[index + 3]))
- Console.WriteLine(keysAfterSelection[index]);
- }
- }
- static List<int> GetFactors(int number)
- {
- int currentFactor = 2;
- List<int> result = new List<int>();
- while (number > 1)
- {
- if (number % currentFactor == 0)
- {
- result.Add(currentFactor);
- number /= currentFactor;
- currentFactor = 2;
- }
- else
- currentFactor++;
- }
- return result;
- }
- static bool ContainsFourPrimeFactors(List<int> factors)
- {
- var noRepetitionsFactors = factors.Distinct();
- if (noRepetitionsFactors.Count() == 4) return true;
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement