結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー tenten
提出日時 2020-10-15 19:36:24
言語 Java
(openjdk 23)
結果
AC  
実行時間 144 ms / 1,000 ms
コード長 608 bytes
コンパイル時間 2,661 ms
コンパイル使用メモリ 74,296 KB
実行使用メモリ 41,916 KB
最終ジャッジ日時 2024-07-20 19:54:00
合計ジャッジ時間 8,453 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

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