結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー jp_stejp_ste
提出日時 2016-02-17 12:26:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 1,000 ms
コード長 753 bytes
コンパイル時間 2,405 ms
コンパイル使用メモリ 76,908 KB
実行使用メモリ 58,192 KB
最終ジャッジ日時 2023-10-22 06:11:32
合計ジャッジ時間 8,689 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
57,908 KB
testcase_01 AC 138 ms
57,516 KB
testcase_02 AC 139 ms
57,568 KB
testcase_03 AC 140 ms
57,452 KB
testcase_04 AC 136 ms
57,444 KB
testcase_05 AC 139 ms
57,708 KB
testcase_06 AC 140 ms
57,500 KB
testcase_07 AC 139 ms
57,548 KB
testcase_08 AC 134 ms
57,484 KB
testcase_09 AC 139 ms
57,508 KB
testcase_10 AC 133 ms
55,740 KB
testcase_11 AC 140 ms
57,436 KB
testcase_12 AC 137 ms
57,504 KB
testcase_13 AC 139 ms
57,716 KB
testcase_14 AC 133 ms
57,620 KB
testcase_15 AC 143 ms
57,772 KB
testcase_16 AC 140 ms
57,408 KB
testcase_17 AC 139 ms
57,520 KB
testcase_18 AC 136 ms
57,532 KB
testcase_19 AC 139 ms
55,556 KB
testcase_20 AC 133 ms
57,500 KB
testcase_21 AC 137 ms
57,704 KB
testcase_22 AC 137 ms
57,556 KB
testcase_23 AC 135 ms
57,592 KB
testcase_24 AC 136 ms
57,840 KB
testcase_25 AC 135 ms
57,572 KB
testcase_26 AC 133 ms
57,764 KB
testcase_27 AC 134 ms
57,568 KB
testcase_28 AC 134 ms
57,484 KB
testcase_29 AC 137 ms
57,680 KB
testcase_30 AC 133 ms
57,516 KB
testcase_31 AC 137 ms
58,192 KB
testcase_32 AC 135 ms
57,460 KB
testcase_33 AC 137 ms
57,804 KB
testcase_34 AC 136 ms
57,368 KB
testcase_35 AC 134 ms
57,580 KB
testcase_36 AC 135 ms
57,748 KB
権限があれば一括ダウンロードができます

ソースコード

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;
		if(a == b) {
			ans = a;
		} else if(a > b) {
			ans = gcd(b, a-b);
		} else if(a < b) {
			ans = gcd(a, b-a);
		}
		return ans;
	}
}
0