Advertisement
mimiiovkova

Untitled

Oct 10th, 2020
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.CompilerServices;
  5.  
  6. namespace List_of_Predicates
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int n = int.Parse(Console.ReadLine());
  13.             List<int> numbers = new List<int>();
  14.             Action<List<int>> print = x => Console.Write(String.Join(" ", x));
  15.  
  16.             for (int i = 1; i <= n; i++)
  17.             {
  18.                 numbers.Add(i);
  19.             }
  20.  
  21.             List<int> dividers = Console.ReadLine().Split().Select(int.Parse).ToList();
  22.             List<int> result = new List<int>();
  23.  
  24.             Func<int, int, bool> divIsTrue = (x, y) => x % y == 0;
  25.             Func<int, int, bool> divIsFalse = (x, y) => x % y == 0;
  26.  
  27.             for (int i = 1; i <= numbers.Count; i++)
  28.             {
  29.                 bool isDivisableTrue = false;
  30.                 bool isDivisableFalse = true;
  31.                
  32.                 foreach (var divider in dividers)
  33.                 {
  34.                    isDivisableTrue =  divIsTrue(i, divider);
  35.                    isDivisableFalse = divIsFalse(i, divider);
  36.                 }
  37.  
  38.                 if (isDivisableTrue && isDivisableFalse)
  39.                 {
  40.                     result.Add(i);
  41.                 }
  42.             }
  43.  
  44.             print(result);
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement