結果

問題 No.1350 2019-6problem
ユーザー ks2mks2m
提出日時 2021-01-17 13:08:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 886 bytes
コンパイル時間 4,759 ms
コンパイル使用メモリ 74,996 KB
実行使用メモリ 50,060 KB
最終ジャッジ日時 2023-08-19 18:44:32
合計ジャッジ時間 7,220 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
50,060 KB
testcase_01 AC 41 ms
49,712 KB
testcase_02 AC 41 ms
49,496 KB
testcase_03 AC 41 ms
49,696 KB
testcase_04 AC 41 ms
49,536 KB
testcase_05 AC 41 ms
49,408 KB
testcase_06 AC 41 ms
49,704 KB
testcase_07 AC 41 ms
49,560 KB
testcase_08 AC 41 ms
49,668 KB
testcase_09 AC 41 ms
49,424 KB
testcase_10 AC 41 ms
49,588 KB
testcase_11 AC 40 ms
47,572 KB
testcase_12 AC 41 ms
49,532 KB
testcase_13 AC 40 ms
49,516 KB
testcase_14 AC 41 ms
49,680 KB
testcase_15 AC 41 ms
49,448 KB
testcase_16 AC 41 ms
49,440 KB
testcase_17 AC 41 ms
49,436 KB
testcase_18 AC 41 ms
49,564 KB
testcase_19 AC 40 ms
49,548 KB
testcase_20 AC 40 ms
49,640 KB
testcase_21 AC 41 ms
49,504 KB
testcase_22 AC 41 ms
49,608 KB
testcase_23 AC 41 ms
49,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		long a = Integer.parseInt(sa[0]);
		long b = Integer.parseInt(sa[1]);
		long k = Integer.parseInt(sa[2]);
		br.close();

		long c = lcm(a, b);
		long ok = a * k;
		long ng = 0;
		while (Math.abs(ok - ng) > 1) {
			long mid = (ok + ng) / 2;
			long aa = mid / a;
			long bb = mid / b;
			long cc = mid / c;
			if (aa + bb - cc >= k) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		System.out.println(ok);
	}

	static long lcm(long a, long b) {
		BigInteger ba = BigInteger.valueOf(a);
		BigInteger bb = BigInteger.valueOf(b);
		return ba.multiply(bb).divide(ba.gcd(bb)).longValue();
	}
}
0