結果

問題 No.141 魔法少女コバ
ユーザー memmemmimemmemmi
提出日時 2018-09-19 13:45:08
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 684 ms / 5,000 ms
コード長 946 bytes
コンパイル時間 945 ms
コンパイル使用メモリ 109,864 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-18 08:14:21
合計ジャッジ時間 6,279 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 93
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

int gcd(int a, int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}

int main() {
    int m,n;
    cin>>m>>n;
    int d = gcd(m,n);
    m/=d; n/=d;//m,nは互いに素
    
    ll cost = 0LL;
    while(m!=n){
        if(m<1||n<1)break;
        if(m>n)m-=n;
        else swap(m,n); 
        cost++;
    }
    
    cout<<cost<<endl;
    
    return 0;
}
0