結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー ほげ太郎ほげ太郎
提出日時 2018-02-26 17:34:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 766 bytes
コンパイル時間 2,674 ms
コンパイル使用メモリ 72,508 KB
実行使用メモリ 56,728 KB
最終ジャッジ日時 2023-08-15 22:17:30
合計ジャッジ時間 8,746 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
56,728 KB
testcase_01 AC 115 ms
56,220 KB
testcase_02 AC 113 ms
55,704 KB
testcase_03 AC 112 ms
55,676 KB
testcase_04 AC 111 ms
55,820 KB
testcase_05 AC 113 ms
56,188 KB
testcase_06 AC 115 ms
55,568 KB
testcase_07 AC 112 ms
55,820 KB
testcase_08 AC 115 ms
56,552 KB
testcase_09 AC 127 ms
55,744 KB
testcase_10 AC 120 ms
56,004 KB
testcase_11 AC 113 ms
55,596 KB
testcase_12 AC 112 ms
56,184 KB
testcase_13 AC 112 ms
55,808 KB
testcase_14 AC 112 ms
55,760 KB
testcase_15 AC 113 ms
55,736 KB
testcase_16 AC 113 ms
55,580 KB
testcase_17 AC 114 ms
56,016 KB
testcase_18 AC 112 ms
55,904 KB
testcase_19 AC 110 ms
55,952 KB
testcase_20 AC 118 ms
56,208 KB
testcase_21 AC 113 ms
56,052 KB
testcase_22 AC 113 ms
55,896 KB
testcase_23 AC 114 ms
55,680 KB
testcase_24 AC 113 ms
56,104 KB
testcase_25 AC 117 ms
55,948 KB
testcase_26 AC 115 ms
55,916 KB
testcase_27 AC 112 ms
56,124 KB
testcase_28 AC 114 ms
55,776 KB
testcase_29 AC 115 ms
55,668 KB
testcase_30 AC 114 ms
56,184 KB
testcase_31 AC 118 ms
55,600 KB
testcase_32 AC 116 ms
55,820 KB
testcase_33 AC 113 ms
56,108 KB
testcase_34 AC 116 ms
55,784 KB
testcase_35 AC 115 ms
55,804 KB
testcase_36 AC 113 ms
55,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] p) {
        Scanner q = new Scanner(System.in);
        long n = q.nextLong();
        int a = q.nextInt();
        int b = q.nextInt();
        int c = q.nextInt();

        long ab = lcm(a, b);
        long bc = lcm(b, c);
        long ca = lcm(c, a);
        long abc = lcm(ab, c);

        System.out.println((n / a + n / b + n / c) - (n / ab + n / bc + n / ca) + n / abc);
    }

    private static long lcm(long a, long b) {
        long min = Math.min(a, b);
        long last = 0;
        for (long r = Math.max(a, b); r != 0;) {
            last = r;
            r = Math.abs(min - r);
            min = Math.min(min, last);
        }
        return a * b / last;
    }
}
0