結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー tentententen
提出日時 2022-07-30 12:27:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 40 ms / 1,000 ms
コード長 1,479 bytes
コンパイル時間 1,840 ms
コンパイル使用メモリ 73,972 KB
実行使用メモリ 49,584 KB
最終ジャッジ日時 2023-09-27 14:51:59
合計ジャッジ時間 4,870 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
49,364 KB
testcase_01 AC 37 ms
49,276 KB
testcase_02 AC 36 ms
49,336 KB
testcase_03 AC 38 ms
49,448 KB
testcase_04 AC 38 ms
49,352 KB
testcase_05 AC 38 ms
49,376 KB
testcase_06 AC 40 ms
49,344 KB
testcase_07 AC 40 ms
49,236 KB
testcase_08 AC 37 ms
49,292 KB
testcase_09 AC 38 ms
49,356 KB
testcase_10 AC 39 ms
49,528 KB
testcase_11 AC 37 ms
49,440 KB
testcase_12 AC 37 ms
49,284 KB
testcase_13 AC 38 ms
49,248 KB
testcase_14 AC 37 ms
49,328 KB
testcase_15 AC 37 ms
49,356 KB
testcase_16 AC 37 ms
49,252 KB
testcase_17 AC 36 ms
49,256 KB
testcase_18 AC 37 ms
49,352 KB
testcase_19 AC 36 ms
49,516 KB
testcase_20 AC 36 ms
49,296 KB
testcase_21 AC 37 ms
49,360 KB
testcase_22 AC 37 ms
49,448 KB
testcase_23 AC 38 ms
49,256 KB
testcase_24 AC 37 ms
49,520 KB
testcase_25 AC 37 ms
49,244 KB
testcase_26 AC 37 ms
49,312 KB
testcase_27 AC 38 ms
49,296 KB
testcase_28 AC 37 ms
49,424 KB
testcase_29 AC 38 ms
49,424 KB
testcase_30 AC 38 ms
49,264 KB
testcase_31 AC 38 ms
49,584 KB
testcase_32 AC 37 ms
49,220 KB
testcase_33 AC 39 ms
49,268 KB
testcase_34 AC 37 ms
49,332 KB
testcase_35 AC 38 ms
49,352 KB
testcase_36 AC 37 ms
49,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();
        long ans = n / a + n / b + n / c - n / getLCM(a, b) - n / getLCM(b, c) - n / getLCM(c, a) + n / getLCM(a, b, c);
        System.out.println(ans);
    }
    
    static long getLCM(long a, long b) {
        return a / getGCD(a, b) * b;
    }
    
    static long getLCM(long a, long b, long c) {
        return getLCM(a, getLCM(b, c));
    }
    
    static long getGCD(long a, long b) {
        if (b == 0) {
            return a;
        } else {
            return getGCD(b, a % b);
        }
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0