結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー samplelpmassamplelpmas
提出日時 2017-05-03 20:05:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 1,000 ms
コード長 739 bytes
コンパイル時間 4,414 ms
コンパイル使用メモリ 71,116 KB
実行使用メモリ 53,520 KB
最終ジャッジ日時 2023-10-12 08:01:49
合計ジャッジ時間 10,778 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
39,068 KB
testcase_01 AC 129 ms
53,520 KB
testcase_02 AC 122 ms
39,156 KB
testcase_03 AC 130 ms
39,836 KB
testcase_04 AC 124 ms
39,448 KB
testcase_05 AC 125 ms
39,544 KB
testcase_06 AC 125 ms
39,332 KB
testcase_07 AC 124 ms
39,296 KB
testcase_08 AC 123 ms
40,328 KB
testcase_09 AC 123 ms
39,264 KB
testcase_10 AC 122 ms
39,156 KB
testcase_11 AC 122 ms
39,524 KB
testcase_12 AC 124 ms
39,444 KB
testcase_13 AC 126 ms
39,428 KB
testcase_14 AC 122 ms
39,396 KB
testcase_15 AC 120 ms
39,376 KB
testcase_16 AC 125 ms
39,516 KB
testcase_17 AC 129 ms
40,340 KB
testcase_18 AC 126 ms
39,656 KB
testcase_19 AC 127 ms
39,528 KB
testcase_20 AC 125 ms
39,840 KB
testcase_21 AC 127 ms
39,432 KB
testcase_22 AC 127 ms
38,972 KB
testcase_23 AC 124 ms
39,872 KB
testcase_24 AC 122 ms
39,620 KB
testcase_25 AC 124 ms
39,128 KB
testcase_26 AC 129 ms
39,564 KB
testcase_27 AC 129 ms
39,564 KB
testcase_28 AC 123 ms
39,888 KB
testcase_29 AC 123 ms
39,260 KB
testcase_30 AC 123 ms
39,764 KB
testcase_31 AC 124 ms
39,108 KB
testcase_32 AC 125 ms
39,620 KB
testcase_33 AC 123 ms
39,768 KB
testcase_34 AC 131 ms
39,208 KB
testcase_35 AC 124 ms
39,160 KB
testcase_36 AC 125 ms
39,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        long N = sc.nextInt();

        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();

        long lcmAB = lcm(a, b);
        long lcmBC = lcm(b, c);
        long lcmCA = lcm(c, a);

        long lcmABC = lcm(lcmAB, c);

        long answer = (N / a) + (N / b) + (N / c) + (N / lcmABC) - (N / lcmAB) - (N / lcmBC) - (N / lcmCA);

        System.out.println(answer);

    }

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    private static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

}
0