結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー tentententen
提出日時 2020-10-15 19:36:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 116 ms / 1,000 ms
コード長 608 bytes
コンパイル時間 1,790 ms
コンパイル使用メモリ 70,652 KB
実行使用メモリ 57,636 KB
最終ジャッジ日時 2023-09-28 01:17:04
合計ジャッジ時間 7,393 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
56,064 KB
testcase_01 AC 108 ms
56,524 KB
testcase_02 AC 111 ms
56,288 KB
testcase_03 AC 110 ms
56,124 KB
testcase_04 AC 111 ms
56,312 KB
testcase_05 AC 108 ms
55,456 KB
testcase_06 AC 107 ms
55,652 KB
testcase_07 AC 111 ms
56,032 KB
testcase_08 AC 109 ms
55,836 KB
testcase_09 AC 110 ms
57,636 KB
testcase_10 AC 110 ms
56,416 KB
testcase_11 AC 110 ms
56,292 KB
testcase_12 AC 108 ms
56,160 KB
testcase_13 AC 107 ms
55,892 KB
testcase_14 AC 107 ms
56,220 KB
testcase_15 AC 113 ms
55,916 KB
testcase_16 AC 109 ms
56,160 KB
testcase_17 AC 108 ms
56,064 KB
testcase_18 AC 108 ms
55,784 KB
testcase_19 AC 111 ms
56,444 KB
testcase_20 AC 111 ms
55,632 KB
testcase_21 AC 110 ms
56,256 KB
testcase_22 AC 114 ms
56,052 KB
testcase_23 AC 115 ms
55,608 KB
testcase_24 AC 116 ms
55,804 KB
testcase_25 AC 116 ms
55,688 KB
testcase_26 AC 113 ms
55,940 KB
testcase_27 AC 113 ms
55,840 KB
testcase_28 AC 112 ms
56,432 KB
testcase_29 AC 114 ms
55,940 KB
testcase_30 AC 112 ms
55,304 KB
testcase_31 AC 111 ms
56,056 KB
testcase_32 AC 109 ms
56,288 KB
testcase_33 AC 109 ms
55,664 KB
testcase_34 AC 112 ms
55,968 KB
testcase_35 AC 113 ms
56,136 KB
testcase_36 AC 111 ms
55,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		long 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