結果
問題 | No.141 魔法少女コバ |
ユーザー |
|
提出日時 | 2016-03-05 22:36:57 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 476 ms / 5,000 ms |
コード長 | 1,199 bytes |
コンパイル時間 | 759 ms |
コンパイル使用メモリ | 85,216 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-24 14:32:48 |
合計ジャッジ時間 | 5,196 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 93 |
ソースコード
#include <iostream>#include <string>#include <vector>#include <queue>#include <stack>#include <map>#include <algorithm>#include <numeric>#include <functional>#include <set>#include <sstream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <cctype>#include <climits>#include <fstream>#include <bitset>#include <time.h>#define ll long long#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)#define RFOR(i,a) for(int i=(a); i >= 0; --i)#define FOE(i,a) for(auto i : a)#define ALL(c) (c).begin(), (c).end()#define RALL(c) (c).rbegin(), (c).rend()#define DUMP(x) cerr << #x << " = " << (x) << endl;#define SUM(x) std::accumulate(ALL(x), 0LL)#define EPS 1e-14using namespace std;// aとbの最大公約数int gcd(int a, int b) {if (b == 0) return a;return gcd(b, a % b);}int main(int argc, char *argv[]) {int M, N;cin >> M >> N;int g = gcd(M, N);M /= g;N /= g;int ans = 0;while (M > 1 || N > 1) {if (M >= N) {M -= N;}else {swap(M, N);}ans++;}cout << ((M == 1 && N == 1) ? ans : -1) << endl;return 0;}