結果
| 問題 | No.1350 2019-6problem |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-01-18 14:20:27 |
| 言語 | Java (openjdk 25.0.2) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 954 bytes |
| 記録 | |
| コンパイル時間 | 1,537 ms |
| コンパイル使用メモリ | 83,704 KB |
| 実行使用メモリ | 538,816 KB |
| 最終ジャッジ日時 | 2026-05-24 22:28:30 |
| 合計ジャッジ時間 | 5,554 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | MLE * 1 -- * 20 |
ソースコード
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();
long lcm = getLCM(a, b);
long count = lcm / a - 1 + lcm / b;
int k = sc.nextInt();
long times = k / count;
long mod = k % count;
TreeSet<Long> set = new TreeSet<>();
for (long i = 1; i * a < lcm; i++) {
set.add(i * a);
}
for (long i = 1; i * b < lcm; i++) {
set.add(i * b);
}
if (mod == 0) {
long ans = lcm * times;
System.out.println(ans);
} else {
long ans = lcm * times;
for (int i = 1; i < mod; i++) {
set.pollFirst();
}
ans += set.first();
System.out.println(ans);
}
}
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);
}
}
}
tenten