結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー jp_ste
提出日時 2016-02-17 12:33:40
言語 Java
(openjdk 23)
結果
AC  
実行時間 142 ms / 1,000 ms
コード長 844 bytes
コンパイル時間 2,364 ms
コンパイル使用メモリ 76,652 KB
実行使用メモリ 54,444 KB
最終ジャッジ日時 2024-11-21 12:18:04
合計ジャッジ時間 8,381 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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);
		int N = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		
		if(a==1 || b==1 || c==1) {
			System.out.println(N);
			
		} else {
			long d = a * b / gcd(a , b);
	        long e = b * c / gcd(b , c);
	        long f = c * a / gcd(c , a);
	        long g = c * d / gcd(c , d);
	        long ans = N / a + N / b + N / c - (N / d + N / e + N / f) + N / g;
			System.out.println(ans);
		}
	}
	
	static long gcd(long a, long b) {
		long ans = 0;
		while(true) {
			if(a == b) {
				ans = a;
				break;
				
			} else if(a > b) {
				long tmp = a-b;
				a = b;
				b = tmp;
				
			} else if( a < b) {
				long tmp = b-a;
				a = a;
				b = tmp;
			}
		}
		return ans;
	}
}
0