結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー rf141rf141
提出日時 2015-12-19 16:05:13
言語 Java
(openjdk 23)
結果
AC  
実行時間 141 ms / 1,000 ms
コード長 493 bytes
コンパイル時間 2,485 ms
コンパイル使用メモリ 74,544 KB
実行使用メモリ 54,544 KB
最終ジャッジ日時 2024-11-21 12:11:43
合計ジャッジ時間 8,277 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Main{
	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		System.out.println(n/a+n/b+n/c - (n/lcm(a,b)+n/lcm(b,c)+n/lcm(c,a)) + n/lcm(a,lcm(b,c)));
	}

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

	public static long lcm(long a,long b){
		return a*b/gcd(a,b);
	}
}
0