using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("100"); WillReturn.Add("2 3 5"); //74 //1以上100以下の範囲内には, //2または3または5の倍数となる数字の個数が合計で74個あります } else if (InputPattern == "Input2") { WillReturn.Add("100"); WillReturn.Add("2 5 6"); //60 } else if (InputPattern == "Input3") { WillReturn.Add("346346"); WillReturn.Add("25 575 2525"); //13853 } else if (InputPattern == "Input4") { WillReturn.Add("83359640"); WillReturn.Add("3304 9805 9945"); //42104 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } //No.316 もっと刺激的なFizzBuzzをください static void Main() { List InputList = GetInputList(); long N = long.Parse(InputList[0]); long[] wkArr = InputList[1].Split(' ').Select(X => long.Parse(X)).ToArray(); long a = wkArr[0]; long b = wkArr[1]; long c = wkArr[2]; //包除原理 N(A∪B∪C)=N(A)+N(B)+N(C)-N(A∩B)-N(A∩C)-N(B∩C)+N(A∩B∩C)で解く long LCMab = a * b / DeriveGCD(a, b); long LCMac = a * c / DeriveGCD(a, c); long LCMbc = b * c / DeriveGCD(b, c); long LCMabc = LCMab * c / DeriveGCD(LCMab, c); //Console.WriteLine("{0}と{1}とのLCM={2}", a, b, LCMab); //Console.WriteLine("{0}と{1}とのLCM={2}", a, c, LCMac); //Console.WriteLine("{0}と{1}とのLCM={2}", b, c, LCMbc); //Console.WriteLine("{0}と{1}と{2}のLCM={3}", a,b, c, LCMabc); long Na = N / a; long Nb = N / b; long Nc = N / c; long Nab = N / LCMab; long Nac = N / LCMac; long Nbc = N / LCMbc; long Nabc = N / LCMabc; Console.WriteLine(Na + Nb + Nc - Nab - Nac - Nbc + Nabc); } //ユークリッドの互除法で2数の最大公約数を求める static long DeriveGCD(long pVal1, long pVal2) { long WarareruKazu = pVal2; long WaruKazu = pVal1; while (true) { long Amari = WarareruKazu % WaruKazu; if (Amari == 0) return WaruKazu; WarareruKazu = WaruKazu; WaruKazu = Amari; } } }