Advertisement
Guest User

09. List Of Predicates

a guest
Feb 6th, 2018
1,221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Rextester
  7. {
  8.     public class Program
  9.     {
  10.         public static void Main(string[] args)
  11.         {
  12.             int length = int.Parse(Console.ReadLine());
  13.             List<int> deviders = Console.ReadLine().Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  14.                 .Select(int.Parse)
  15.                 .Distinct()
  16.                 .ToList();
  17.            
  18.             List<int> numbers = new List<int>();
  19.             for (int i = 1; i <= length; i++)
  20.             {
  21.                 if (DevidersInfo(i, deviders))
  22.                 {
  23.                 numbers.Add(i);
  24.                 }
  25.             }
  26.            
  27.             Console.WriteLine(string.Join(" ", numbers));
  28.         }
  29.  
  30.         private static bool DevidersInfo(int n, List<int> deviders)
  31.         {
  32.             bool isTrue = true;
  33.             foreach (int divaider in deviders)
  34.             {
  35.                 if (n % divaider != 0)
  36.                 {
  37.                     isTrue = false;
  38.                 }
  39.             }
  40.             return isTrue;
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement