結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー GrenacheGrenache
提出日時 2015-12-09 00:07:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 45 ms / 1,000 ms
コード長 2,018 bytes
コンパイル時間 3,819 ms
コンパイル使用メモリ 74,988 KB
実行使用メモリ 49,724 KB
最終ジャッジ日時 2023-08-13 15:28:41
合計ジャッジ時間 6,537 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,384 KB
testcase_01 AC 43 ms
49,340 KB
testcase_02 AC 43 ms
49,492 KB
testcase_03 AC 43 ms
49,248 KB
testcase_04 AC 43 ms
49,500 KB
testcase_05 AC 43 ms
49,364 KB
testcase_06 AC 43 ms
49,536 KB
testcase_07 AC 42 ms
49,308 KB
testcase_08 AC 42 ms
49,484 KB
testcase_09 AC 43 ms
49,372 KB
testcase_10 AC 42 ms
47,448 KB
testcase_11 AC 42 ms
49,300 KB
testcase_12 AC 43 ms
49,300 KB
testcase_13 AC 43 ms
49,536 KB
testcase_14 AC 43 ms
49,704 KB
testcase_15 AC 43 ms
47,388 KB
testcase_16 AC 42 ms
49,636 KB
testcase_17 AC 42 ms
49,708 KB
testcase_18 AC 42 ms
49,424 KB
testcase_19 AC 42 ms
49,296 KB
testcase_20 AC 42 ms
49,316 KB
testcase_21 AC 42 ms
49,624 KB
testcase_22 AC 42 ms
49,480 KB
testcase_23 AC 43 ms
49,724 KB
testcase_24 AC 43 ms
49,372 KB
testcase_25 AC 45 ms
49,304 KB
testcase_26 AC 43 ms
49,544 KB
testcase_27 AC 43 ms
49,344 KB
testcase_28 AC 43 ms
49,304 KB
testcase_29 AC 43 ms
49,268 KB
testcase_30 AC 43 ms
49,252 KB
testcase_31 AC 42 ms
49,292 KB
testcase_32 AC 43 ms
49,548 KB
testcase_33 AC 43 ms
49,336 KB
testcase_34 AC 43 ms
49,296 KB
testcase_35 AC 43 ms
49,304 KB
testcase_36 AC 43 ms
49,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;


public class Main_yukicoder316 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Printer pr = new Printer(System.out);

        long n = sc.nextInt();
        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();

        long ab = lcm(a, b);
        long bc = lcm(b, c);
        long ca = lcm(c, a);
        long abc = lcm(ab, c);

        long ret = n / a + n / b + n / c - n / ab - n / bc - n / ca + n / abc;

        pr.println(ret);

        pr.close();
        sc.close();
    }

	private static long lcm(long n, long m) {
		return n / gcd(n, m) * m;
	}

	private static long gcd(long n, long m) {
		if (m == 0) {
			return n;
		} else {
			return gcd(m, n % m);
		}
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		BufferedReader br;
		Iterator<String> it;

		Scanner (InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}

		String next() throws RuntimeException  {
			try {
				if (it == null || !it.hasNext()) {
					it = Arrays.asList(br.readLine().split(" ")).iterator();
				}
				return it.next();
			} catch (IOException e) {
				throw new IllegalStateException();
			}
		}

		int nextInt() throws RuntimeException {
			return Integer.parseInt(next());
		}

		long nextLong() throws RuntimeException {
			return Long.parseLong(next());
		}

		float nextFloat() throws RuntimeException {
			return Float.parseFloat(next());
		}

		double nextDouble() throws RuntimeException {
			return Double.parseDouble(next());
		}

		void close() {
			try {
				br.close();
			} catch (IOException e) {
//				throw new IllegalStateException();
			}
		}
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0