結果

問題 No.176 2種類の切手
ユーザー htensaihtensai
提出日時 2020-01-14 18:23:48
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 826 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 71,448 KB
実行使用メモリ 56,468 KB
最終ジャッジ日時 2023-08-26 22:12:21
合計ジャッジ時間 6,887 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,368 KB
testcase_01 AC 117 ms
55,688 KB
testcase_02 AC 117 ms
54,380 KB
testcase_03 AC 118 ms
55,988 KB
testcase_04 AC 120 ms
55,732 KB
testcase_05 AC 119 ms
55,964 KB
testcase_06 AC 118 ms
55,684 KB
testcase_07 AC 120 ms
55,920 KB
testcase_08 AC 119 ms
55,864 KB
testcase_09 AC 119 ms
55,688 KB
testcase_10 AC 117 ms
55,836 KB
testcase_11 AC 118 ms
55,604 KB
testcase_12 AC 119 ms
55,936 KB
testcase_13 AC 118 ms
55,420 KB
testcase_14 AC 118 ms
55,436 KB
testcase_15 AC 118 ms
55,944 KB
testcase_16 AC 119 ms
56,028 KB
testcase_17 AC 119 ms
53,948 KB
testcase_18 AC 120 ms
55,784 KB
testcase_19 AC 117 ms
55,652 KB
testcase_20 AC 118 ms
55,372 KB
testcase_21 AC 124 ms
55,804 KB
testcase_22 AC 125 ms
55,628 KB
testcase_23 AC 117 ms
55,920 KB
testcase_24 AC 118 ms
55,680 KB
testcase_25 AC 119 ms
55,592 KB
testcase_26 WA -
testcase_27 AC 119 ms
56,468 KB
testcase_28 AC 117 ms
56,044 KB
testcase_29 WA -
testcase_30 AC 118 ms
55,652 KB
testcase_31 AC 117 ms
55,492 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;
        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