結果
| 問題 |
No.141 魔法少女コバ
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-02-01 23:36:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 678 bytes |
| コンパイル時間 | 567 ms |
| コンパイル使用メモリ | 74,684 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-23 05:33:12 |
| 合計ジャッジ時間 | 2,341 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 93 |
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
long long gcd(long long a, long long b){
if(b==0) return a;
return gcd(b, a%b);
}
// a/b
long long func(int a, int b){
int ret = 0;
if(a==0) return -1;
if(b==1){
ret += a-1;
return ret;
}
if(a>b){
ret += a/b;
a %= b;
}else if(a==b){
return -1;
}else{
swap(a,b);
ret += 1;
}
ret += func(a,b);
return ret;
}
int main(){
long long n,m;
cin >> m >> n;
int g = gcd(n,m);
n/=g;
m/=g;
long long ans = func(m,n);
cout << ans << endl;
return 0;
}
koyumeishi