結果

問題 No.176 2種類の切手
ユーザー chocorusk
提出日時 2018-10-15 15:31:57
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 450 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 57,440 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 18:31:03
合計ジャッジ時間 1,544 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}
int main(){
    ll a, b, t;
    cin>>a>>b>>t;
    if(a*b<=t){
        ll d=gcd(a, b);
        cout<<(t+d-1)/d*d<<endl;
    }else{
        ll ans=1e12;
        for(ll i=0; i*b<t+b; i++){
            ans=min(ans, i*b+(max(0ll, t-i*b)+a-1)/a*a);
        }
        cout<<ans<<endl;
    }
    return 0;
}
0