結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー tentententen
提出日時 2020-10-15 19:35:22
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 607 bytes
コンパイル時間 2,655 ms
コンパイル使用メモリ 71,436 KB
実行使用メモリ 58,044 KB
最終ジャッジ日時 2023-09-28 01:16:55
合計ジャッジ時間 8,694 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,504 KB
testcase_01 AC 112 ms
56,120 KB
testcase_02 WA -
testcase_03 AC 116 ms
55,612 KB
testcase_04 AC 113 ms
55,988 KB
testcase_05 AC 113 ms
55,628 KB
testcase_06 AC 116 ms
56,028 KB
testcase_07 AC 116 ms
55,872 KB
testcase_08 AC 113 ms
55,960 KB
testcase_09 AC 117 ms
55,712 KB
testcase_10 AC 114 ms
55,768 KB
testcase_11 AC 113 ms
55,980 KB
testcase_12 AC 112 ms
55,888 KB
testcase_13 AC 118 ms
55,580 KB
testcase_14 AC 118 ms
58,044 KB
testcase_15 AC 117 ms
56,172 KB
testcase_16 AC 117 ms
53,784 KB
testcase_17 AC 116 ms
56,096 KB
testcase_18 AC 118 ms
55,816 KB
testcase_19 AC 111 ms
55,888 KB
testcase_20 AC 119 ms
55,544 KB
testcase_21 AC 114 ms
55,700 KB
testcase_22 AC 112 ms
55,924 KB
testcase_23 AC 113 ms
55,692 KB
testcase_24 AC 110 ms
55,756 KB
testcase_25 AC 116 ms
56,244 KB
testcase_26 AC 111 ms
56,308 KB
testcase_27 AC 112 ms
55,700 KB
testcase_28 AC 113 ms
55,772 KB
testcase_29 AC 110 ms
55,968 KB
testcase_30 AC 111 ms
55,772 KB
testcase_31 AC 111 ms
55,980 KB
testcase_32 AC 112 ms
55,772 KB
testcase_33 AC 111 ms
55,852 KB
testcase_34 AC 110 ms
55,484 KB
testcase_35 AC 111 ms
55,968 KB
testcase_36 AC 115 ms
55,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		long ans = n / a + n / b + n / c;
		ans -= n / getLCM(a, b) + n / getLCM(b , c) + n / getLCM(c, a);
		ans += n / getLCM(getLCM(a, b), c);
		System.out.println(ans);
	}
	
	static long getLCM(long x, long y) {
	    return x / getGCD(x, y) * y;
	}
	
	static long getGCD(long x, long y) {
	    if (x % y == 0) {
	        return y;
	    } else {
	        return getGCD(y, x % y);
	    }
	}
}
0