Advertisement
Galina841130

List of Predicates

Jan 20th, 2022
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp1
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int endNumber = int.Parse(Console.ReadLine());
  12.             int[] dividers = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  13.             HashSet<int> sortedDividers = new HashSet<int>();
  14.             foreach (int number in dividers)
  15.             {
  16.                 sortedDividers.Add(number);
  17.             }
  18.             if (endNumber <= 0)
  19.             {
  20.                 return;
  21.             }
  22.  
  23.             Func<HashSet<int>, int, bool> isDevisible = (allDividers, number) =>
  24.             {
  25.                 return allDividers.All(x => number % x == 0);
  26.             };
  27.             int[] allDevisibleNumbers = Enumerable.Range(1, endNumber).Where(number => isDevisible(sortedDividers, number)).ToArray();
  28.             Console.WriteLine(string.Join(" ", allDevisibleNumbers));
  29.         }
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement