結果

問題 No.176 2種類の切手
ユーザー htensaihtensai
提出日時 2020-01-14 20:13:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 1,000 ms
コード長 885 bytes
コンパイル時間 5,434 ms
コンパイル使用メモリ 71,028 KB
実行使用メモリ 56,152 KB
最終ジャッジ日時 2023-08-27 01:43:03
合計ジャッジ時間 8,816 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,848 KB
testcase_01 AC 120 ms
55,332 KB
testcase_02 AC 116 ms
56,152 KB
testcase_03 AC 117 ms
56,080 KB
testcase_04 AC 117 ms
55,500 KB
testcase_05 AC 110 ms
55,504 KB
testcase_06 AC 114 ms
55,896 KB
testcase_07 AC 112 ms
55,720 KB
testcase_08 AC 114 ms
53,820 KB
testcase_09 AC 116 ms
55,556 KB
testcase_10 AC 115 ms
53,944 KB
testcase_11 AC 117 ms
56,088 KB
testcase_12 AC 114 ms
55,992 KB
testcase_13 AC 111 ms
55,828 KB
testcase_14 AC 111 ms
55,616 KB
testcase_15 AC 115 ms
55,900 KB
testcase_16 AC 118 ms
55,724 KB
testcase_17 AC 119 ms
55,912 KB
testcase_18 AC 117 ms
56,104 KB
testcase_19 AC 116 ms
55,968 KB
testcase_20 AC 116 ms
55,800 KB
testcase_21 AC 113 ms
55,828 KB
testcase_22 AC 115 ms
55,836 KB
testcase_23 AC 114 ms
56,032 KB
testcase_24 AC 121 ms
55,732 KB
testcase_25 AC 121 ms
55,640 KB
testcase_26 AC 113 ms
55,616 KB
testcase_27 AC 112 ms
55,628 KB
testcase_28 AC 112 ms
55,924 KB
testcase_29 AC 111 ms
55,744 KB
testcase_30 AC 113 ms
56,044 KB
testcase_31 AC 113 ms
55,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
        }
    }
}
0