結果

問題 No.176 2種類の切手
ユーザー Grenache
提出日時 2016-05-31 20:22:14
言語 Java
(openjdk 23)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 856 bytes
コンパイル時間 3,853 ms
コンパイル使用メモリ 77,420 KB
実行使用メモリ 54,300 KB
最終ジャッジ日時 2024-10-08 03:44:21
合計ジャッジ時間 8,336 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

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