結果

問題 No.1350 2019-6problem
ユーザー tentententen
提出日時 2021-01-18 14:28:34
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 727 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 72,168 KB
実行使用メモリ 56,152 KB
最終ジャッジ日時 2023-08-20 21:43:16
合計ジャッジ時間 6,185 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,576 KB
testcase_01 AC 125 ms
55,564 KB
testcase_02 AC 124 ms
56,152 KB
testcase_03 AC 125 ms
55,620 KB
testcase_04 AC 132 ms
55,616 KB
testcase_05 AC 126 ms
55,660 KB
testcase_06 AC 128 ms
55,676 KB
testcase_07 AC 125 ms
55,620 KB
testcase_08 AC 128 ms
55,948 KB
testcase_09 AC 124 ms
55,932 KB
testcase_10 AC 123 ms
55,648 KB
testcase_11 AC 126 ms
55,644 KB
testcase_12 AC 126 ms
55,536 KB
testcase_13 AC 126 ms
55,944 KB
testcase_14 AC 125 ms
55,320 KB
testcase_15 AC 125 ms
55,352 KB
testcase_16 AC 126 ms
55,748 KB
testcase_17 AC 125 ms
55,616 KB
testcase_18 AC 125 ms
55,628 KB
testcase_19 AC 126 ms
55,660 KB
testcase_20 AC 126 ms
55,728 KB
testcase_21 AC 127 ms
55,344 KB
testcase_22 AC 125 ms
55,324 KB
testcase_23 AC 125 ms
55,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		long lcm = getLCM(a, b);
		long left = 0;
		long right = Long.MAX_VALUE / 2;
		while (right - left > 1) {
		    long m = (left + right) / 2;
		    long count = m / a + m / b - m / lcm;
		    if (count >= k) {
		        right = m;
		    } else {
		        left = m;
		    }
		}
	    System.out.println(right);
	}
	
	static long getLCM(long a, long b) {
	    return a / getGCD(a, b) * b;
	}
	
	static long getGCD(long a, long b) {
	    if (a % b == 0) {
	        return b;
	    } else {
	        return getGCD(b, a % b);
	    }
	}
}
0