結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー jp_stejp_ste
提出日時 2016-02-17 12:33:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 1,000 ms
コード長 844 bytes
コンパイル時間 2,079 ms
コンパイル使用メモリ 76,952 KB
実行使用メモリ 54,408 KB
最終ジャッジ日時 2024-05-01 09:03:56
合計ジャッジ時間 8,159 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
53,880 KB
testcase_01 AC 133 ms
54,136 KB
testcase_02 AC 134 ms
54,208 KB
testcase_03 AC 135 ms
54,096 KB
testcase_04 AC 134 ms
54,064 KB
testcase_05 AC 132 ms
53,972 KB
testcase_06 AC 132 ms
54,052 KB
testcase_07 AC 133 ms
54,104 KB
testcase_08 AC 132 ms
54,408 KB
testcase_09 AC 135 ms
54,092 KB
testcase_10 AC 136 ms
54,092 KB
testcase_11 AC 137 ms
54,096 KB
testcase_12 AC 133 ms
54,220 KB
testcase_13 AC 136 ms
54,232 KB
testcase_14 AC 132 ms
54,012 KB
testcase_15 AC 129 ms
54,056 KB
testcase_16 AC 132 ms
54,184 KB
testcase_17 AC 132 ms
54,124 KB
testcase_18 AC 134 ms
41,252 KB
testcase_19 AC 134 ms
41,600 KB
testcase_20 AC 139 ms
42,040 KB
testcase_21 AC 133 ms
41,700 KB
testcase_22 AC 133 ms
41,212 KB
testcase_23 AC 133 ms
41,624 KB
testcase_24 AC 136 ms
41,800 KB
testcase_25 AC 132 ms
41,968 KB
testcase_26 AC 131 ms
41,296 KB
testcase_27 AC 132 ms
41,316 KB
testcase_28 AC 139 ms
41,292 KB
testcase_29 AC 135 ms
41,372 KB
testcase_30 AC 133 ms
41,304 KB
testcase_31 AC 134 ms
41,432 KB
testcase_32 AC 133 ms
41,296 KB
testcase_33 AC 133 ms
41,248 KB
testcase_34 AC 131 ms
41,180 KB
testcase_35 AC 133 ms
41,352 KB
testcase_36 AC 137 ms
41,432 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;
		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