結果

問題 No.176 2種類の切手
ユーザー GrenacheGrenache
提出日時 2016-05-31 20:22:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 1,000 ms
コード長 856 bytes
コンパイル時間 3,560 ms
コンパイル使用メモリ 77,496 KB
実行使用メモリ 41,944 KB
最終ジャッジ日時 2024-04-16 22:21:30
合計ジャッジ時間 9,088 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
41,392 KB
testcase_01 AC 135 ms
41,316 KB
testcase_02 AC 130 ms
41,316 KB
testcase_03 AC 132 ms
41,316 KB
testcase_04 AC 133 ms
41,500 KB
testcase_05 AC 132 ms
41,468 KB
testcase_06 AC 134 ms
41,676 KB
testcase_07 AC 133 ms
41,444 KB
testcase_08 AC 134 ms
41,524 KB
testcase_09 AC 133 ms
41,944 KB
testcase_10 AC 130 ms
41,572 KB
testcase_11 AC 122 ms
40,412 KB
testcase_12 AC 132 ms
41,600 KB
testcase_13 AC 133 ms
41,304 KB
testcase_14 AC 136 ms
41,160 KB
testcase_15 AC 134 ms
41,468 KB
testcase_16 AC 135 ms
41,560 KB
testcase_17 AC 131 ms
41,676 KB
testcase_18 AC 131 ms
41,200 KB
testcase_19 AC 132 ms
41,308 KB
testcase_20 AC 134 ms
41,104 KB
testcase_21 AC 132 ms
41,460 KB
testcase_22 AC 133 ms
41,656 KB
testcase_23 AC 131 ms
41,408 KB
testcase_24 AC 129 ms
41,548 KB
testcase_25 AC 119 ms
40,008 KB
testcase_26 AC 132 ms
41,344 KB
testcase_27 AC 131 ms
41,456 KB
testcase_28 AC 136 ms
41,372 KB
testcase_29 AC 132 ms
41,476 KB
testcase_30 AC 131 ms
41,332 KB
testcase_31 AC 131 ms
41,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder176 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int t = sc.nextInt();

        int m  = (t + b - 1) / b;

        long l = ((long)t / lcm(a, b) - 1) * lcm(a, b) / b;

        int min = Integer.MAX_VALUE;
        for (int i = m; i >= 0 && i >= l; i--) {
        	if (i * b >= t) {
        		min = Math.min(min, i * b);
        	} else {
        		min = Math.min(min, (t - i * b + a - 1) / a * a + i * b);
        	}
        }

        System.out.println(min);

        sc.close();
    }

    private static long lcm(int n, int m) {
		return (long)n / gcd(n, m) * m;
	}

	private static int gcd(int n, int m) {
		if (m == 0) {
			return n;
		} else {
			return gcd(m, n % m);
		}
	}
}
0