結果
| 問題 |
No.176 2種類の切手
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-01-14 20:13:38 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 138 ms / 1,000 ms |
| コード長 | 885 bytes |
| コンパイル時間 | 2,672 ms |
| コンパイル使用メモリ | 74,196 KB |
| 実行使用メモリ | 41,756 KB |
| 最終ジャッジ日時 | 2024-12-26 06:15:51 |
| 合計ジャッジ時間 | 7,737 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 29 |
ソースコード
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long a = sc.nextInt();
long b = sc.nextInt();
long t = sc.nextInt();
long lcm = a / gcd(a, b) * b;
long total = t % lcm;
if (lcm < t) {
total += lcm;
}
long min = Long.MAX_VALUE;
if (b > a) {
long tmp = b;
b = a;
a = tmp;
}
for (int i = 0; i * a < total; i++) {
min = Math.min(min, (total - i * a + b - 1) / b * b - total + i * a);
}
min = Math.min(min, (total + a - 1) / a * a - total);
System.out.println(t + min);
}
static long gcd(long x, long y) {
if (x % y == 0) {
return y;
} else {
return gcd(y, x % y);
}
}
}
htensai