結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー ぴろずぴろず
提出日時 2015-12-09 03:09:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 1,000 ms
コード長 687 bytes
コンパイル時間 2,312 ms
コンパイル使用メモリ 71,324 KB
実行使用メモリ 56,008 KB
最終ジャッジ日時 2023-08-13 15:39:02
合計ジャッジ時間 8,682 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
55,628 KB
testcase_01 AC 129 ms
55,476 KB
testcase_02 AC 128 ms
55,660 KB
testcase_03 AC 128 ms
55,864 KB
testcase_04 AC 128 ms
55,684 KB
testcase_05 AC 129 ms
55,880 KB
testcase_06 AC 132 ms
55,688 KB
testcase_07 AC 127 ms
55,616 KB
testcase_08 AC 127 ms
55,828 KB
testcase_09 AC 128 ms
55,732 KB
testcase_10 AC 129 ms
55,708 KB
testcase_11 AC 129 ms
55,760 KB
testcase_12 AC 127 ms
55,800 KB
testcase_13 AC 129 ms
55,740 KB
testcase_14 AC 129 ms
55,736 KB
testcase_15 AC 130 ms
55,452 KB
testcase_16 AC 130 ms
55,700 KB
testcase_17 AC 127 ms
55,740 KB
testcase_18 AC 132 ms
55,688 KB
testcase_19 AC 127 ms
55,896 KB
testcase_20 AC 127 ms
55,768 KB
testcase_21 AC 128 ms
55,972 KB
testcase_22 AC 128 ms
55,444 KB
testcase_23 AC 129 ms
55,668 KB
testcase_24 AC 129 ms
55,768 KB
testcase_25 AC 129 ms
55,760 KB
testcase_26 AC 127 ms
53,824 KB
testcase_27 AC 130 ms
55,680 KB
testcase_28 AC 128 ms
55,592 KB
testcase_29 AC 128 ms
55,816 KB
testcase_30 AC 127 ms
55,880 KB
testcase_31 AC 127 ms
55,760 KB
testcase_32 AC 127 ms
55,996 KB
testcase_33 AC 126 ms
56,008 KB
testcase_34 AC 129 ms
55,612 KB
testcase_35 AC 127 ms
55,776 KB
testcase_36 AC 127 ms
55,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no316;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long[] a = new long[3];
		for(int i=0;i<3;i++) {
			a[i] = sc.nextLong();
		}
		long count = 0;
		for(int i=1;i<8;i++) {
			long lcm = 1;
			for(int j=0;j<3;j++) {
				if ((i>>j&1)>0) {
					lcm = lcm(lcm,a[j]);
				}
			}
			count += (n / lcm) * (Integer.bitCount(i) % 2 == 1 ? 1 : -1); 
		}
		System.out.println(count);
	}

	public static long gcd(long a,long b) {
		while(b!=0) {
			long r = a%b;
			a = b;
			b = r;
		}
		return a;
	}
	public static long lcm(long a,long b) {
		return a / gcd(a,b) * b;
	}


}
0