結果

問題 No.894 二種類のバス
ユーザー 37zigen
提出日時 2018-02-21 07:47:09
言語 Java
(openjdk 23)
結果
AC  
実行時間 134 ms / 1,000 ms
コード長 870 bytes
コンパイル時間 2,274 ms
コンパイル使用メモリ 78,596 KB
実行使用メモリ 54,400 KB
最終ジャッジ日時 2024-09-14 08:37:47
合計ジャッジ時間 5,756 ms
ジャッジサーバーID
(参考情報)
judge5 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		long t = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		if (!(1 <= t && 1 <= a && 1 <= b && t <= 1e18 && a <= 1e18 && b <= 1e18))
			throw new AssertionError();

		BigInteger T = BigInteger.valueOf(t).subtract(BigInteger.ONE);
		BigInteger A = BigInteger.valueOf(a);
		BigInteger B = BigInteger.valueOf(b);

		BigInteger ans = BigInteger.ZERO;
		ans = ans.add(T.divide(A));
		ans = ans.add(T.divide(B));
		ans = ans.subtract(T.divide(A.multiply(B).divide(A.gcd(B))));
		ans = ans.add(BigInteger.ONE);
		System.out.println(ans);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0