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.Runtime.CompilerServices;
- namespace List_of_Predicates
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- List<int> numbers = new List<int>();
- Action<List<int>> print = x => Console.Write(String.Join(" ", x));
- for (int i = 1; i <= n; i++)
- {
- numbers.Add(i);
- }
- List<int> dividers = Console.ReadLine().Split().Select(int.Parse).ToList();
- List<int> result = new List<int>();
- Func<int, int, bool> divIsTrue = (x, y) => x % y == 0;
- Func<int, int, bool> divIsFalse = (x, y) => x % y == 0;
- for (int i = 1; i <= numbers.Count; i++)
- {
- bool isDivisableTrue = false;
- bool isDivisableFalse = true;
- foreach (var divider in dividers)
- {
- isDivisableTrue = divIsTrue(i, divider);
- isDivisableFalse = divIsFalse(i, divider);
- }
- if (isDivisableTrue && isDivisableFalse)
- {
- result.Add(i);
- }
- }
- print(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement