using System; using System.Collections.Generic; using System.Linq; namespace ConsoleApplication3 { static class Extensions { public static IEnumerable Do(this IEnumerable source, Action process) { foreach (var elem in source) { process(elem); yield return elem; } } public static IEnumerable Repeat(this IEnumerable source, Func condition, Action sideEffect) { foreach (var elem in source) { while (condition(elem)) { sideEffect(elem); yield return elem; } } } } class Program { private static readonly List PrimeNumbers = new List {2, 3}; public static IEnumerable GetPrimeSequence() => PrimeNumbers.Concat(Enumerable.Range((PrimeNumbers.Max() - 1)/2 + 1, 1000000000) .Select(x => x*2 + 1) .Where(x => PrimeNumbers.TakeWhile(p => Math.Sqrt(x) >= p).All(p => x%p != 0)) .Do(x => PrimeNumbers.Add(x))); public static IEnumerable Factorization(int value) { var tmp = value; return GetPrimeSequence().TakeWhile(_ => tmp != 1).Repeat(x => tmp%x == 0, x => tmp/=x); } public static int LeastCommonMultiple(int lParam, int rParam) { var lFact = Factorization(lParam).ToLookup(x => x).Select(x => new {prime = x.Key, value = (int)Math.Pow(x.Key, x.Count()) }); var rFact = Factorization(rParam).ToLookup(x => x).Select(x => new {prime = x.Key, value = (int) Math.Pow(x.Key, x.Count())}); var ret = lFact.Concat(rFact).ToLookup(x => x.prime,x=>x.value); var hoge = ret.Select(x => x.Max()); return hoge.Aggregate(1, (accum, i) => accum *= i); } static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); var ab = LeastCommonMultiple(input[0], input[1]); var bc = LeastCommonMultiple(input[1], input[2]); var ca = LeastCommonMultiple(input[2], input[0]); var med = LeastCommonMultiple(ab, input[2]); var accum = input.Select(x => n/x).Sum(); accum -= n/ab; accum -= n/bc; accum -= n/ca; accum += n/med; Console.WriteLine(accum); } } }