結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー takeya_okinotakeya_okino
提出日時 2019-09-07 01:34:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 860 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 72,264 KB
実行使用メモリ 56,292 KB
最終ジャッジ日時 2023-09-07 06:09:09
合計ジャッジ時間 8,317 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,716 KB
testcase_01 AC 122 ms
54,184 KB
testcase_02 AC 123 ms
55,712 KB
testcase_03 AC 123 ms
55,656 KB
testcase_04 AC 125 ms
55,880 KB
testcase_05 AC 125 ms
55,608 KB
testcase_06 AC 127 ms
56,060 KB
testcase_07 AC 124 ms
56,292 KB
testcase_08 AC 123 ms
55,820 KB
testcase_09 AC 123 ms
55,712 KB
testcase_10 AC 125 ms
55,636 KB
testcase_11 AC 124 ms
55,676 KB
testcase_12 AC 125 ms
55,708 KB
testcase_13 AC 126 ms
55,976 KB
testcase_14 AC 125 ms
55,908 KB
testcase_15 AC 125 ms
56,092 KB
testcase_16 AC 125 ms
55,768 KB
testcase_17 AC 126 ms
55,612 KB
testcase_18 AC 122 ms
55,952 KB
testcase_19 AC 123 ms
55,800 KB
testcase_20 AC 124 ms
55,776 KB
testcase_21 AC 122 ms
55,564 KB
testcase_22 AC 127 ms
55,788 KB
testcase_23 AC 125 ms
55,948 KB
testcase_24 AC 124 ms
55,760 KB
testcase_25 AC 123 ms
55,680 KB
testcase_26 AC 123 ms
55,980 KB
testcase_27 AC 123 ms
55,668 KB
testcase_28 AC 124 ms
53,944 KB
testcase_29 AC 123 ms
55,752 KB
testcase_30 AC 124 ms
55,988 KB
testcase_31 AC 127 ms
55,604 KB
testcase_32 AC 124 ms
55,704 KB
testcase_33 AC 125 ms
55,620 KB
testcase_34 AC 123 ms
55,828 KB
testcase_35 AC 123 ms
55,692 KB
testcase_36 AC 123 ms
56,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long k1 = n / a;
    long k2 = n / b;
    long k3 = n / c;
    long g1 = gcd(a, b);
    long g2 = gcd(a, c);
    long g3 = gcd(b, c);
    long g4 = gcd(a, g3);
    long l1 = g1 * (a / g1) * (b / g1);
    long l2 = g2 * (a / g2) * (c / g2);
    long l3 = g3 * (b / g3) * (c / g3);
    long g5 = gcd(l1, c);
    long l4 = g5 * (l1 / g5) * (c / g5);
    long h1 = n / l1;
    long h2 = n / l2;
    long h3 = n / l3;
    long h4 = n / l4;
    long ans = k1 + k2 + k3 - h1 - h2 - h3 + h4;
    System.out.println(ans);
  }

  public static long gcd(long a, long b) {
    if(b == 0) return a;
    return gcd(b, (a % b));
  }
}
0