結果
問題 | No.316 もっと刺激的なFizzBuzzをください |
ユーザー |
|
提出日時 | 2015-12-09 00:07:19 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 57 ms / 1,000 ms |
コード長 | 2,018 bytes |
コンパイル時間 | 4,635 ms |
コンパイル使用メモリ | 78,216 KB |
実行使用メモリ | 50,624 KB |
最終ジャッジ日時 | 2024-11-21 11:19:12 |
合計ジャッジ時間 | 6,879 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.PrintStream;import java.io.PrintWriter;import java.util.Arrays;import java.util.Iterator;public class Main_yukicoder316 {public static void main(String[] args) {Scanner sc = new Scanner(System.in);Printer pr = new Printer(System.out);long n = sc.nextInt();long a = sc.nextInt();long b = sc.nextInt();long c = sc.nextInt();long ab = lcm(a, b);long bc = lcm(b, c);long ca = lcm(c, a);long abc = lcm(ab, c);long ret = n / a + n / b + n / c - n / ab - n / bc - n / ca + n / abc;pr.println(ret);pr.close();sc.close();}private static long lcm(long n, long m) {return n / gcd(n, m) * m;}private static long gcd(long n, long m) {if (m == 0) {return n;} else {return gcd(m, n % m);}}@SuppressWarnings("unused")private static class Scanner {BufferedReader br;Iterator<String> it;Scanner (InputStream in) {br = new BufferedReader(new InputStreamReader(in));}String next() throws RuntimeException {try {if (it == null || !it.hasNext()) {it = Arrays.asList(br.readLine().split(" ")).iterator();}return it.next();} catch (IOException e) {throw new IllegalStateException();}}int nextInt() throws RuntimeException {return Integer.parseInt(next());}long nextLong() throws RuntimeException {return Long.parseLong(next());}float nextFloat() throws RuntimeException {return Float.parseFloat(next());}double nextDouble() throws RuntimeException {return Double.parseDouble(next());}void close() {try {br.close();} catch (IOException e) {// throw new IllegalStateException();}}}private static class Printer extends PrintWriter {Printer(PrintStream out) {super(out);}}}