結果

問題 No.141 魔法少女コバ
ユーザー kpinkcat
提出日時 2023-10-31 01:19:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 672 bytes
コンパイル時間 1,622 ms
コンパイル使用メモリ 194,112 KB
最終ジャッジ日時 2025-02-17 17:05:46
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 93
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<math.h>
#include<bitset>
using ll = long long;
using namespace std;

int main(){
    int m, n, ans = 0, t;
    cin >> m >> n;
    t = gcd(m, n);
    m /= t;
    n /= t;
    if (n == 1) {
        cout << m - 1 << endl;
        return 0;
    } else if (m > n) {
        while (m > n){
            m -= n;
            ans++;
        }
    }
    while (m != 1){
        swap(m, n);
        ans++;
        while (m > n){
            m -= n;
            ans++;
        }
    }
    cout << ans + n << endl;
}
0