結果

問題 No.316 もっと刺激的なFizzBuzzをください
コンテスト
ユーザー Mcpu3
提出日時 2018-08-27 18:34:00
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 58 ms / 1,000 ms
コード長 545 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,740 ms
コンパイル使用メモリ 81,820 KB
実行使用メモリ 41,600 KB
最終ジャッジ日時 2026-03-26 01:58:02
合計ジャッジ時間 4,949 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.Scanner;

class Main{
	
	public static long gcd(long x,long y) {
		long r;
		if(y>x) {
			r=x;
			x=y;
			y=r;
		}
		while(y>0) {
			r=x%y;
			x=y;
			y=r;
		}
		return x;
	}
	
	public static long lcm(long x,long y) {
		return x*y/gcd(x,y);
	}
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong(),a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong();
		sc.close();
		System.out.print(n/a+n/b+n/c-n/lcm(a,b)-n/lcm(b,c)-n/lcm(a,c)+n/lcm(lcm(a,b),c));
	}
}
0