結果
問題 | No.141 魔法少女コバ |
ユーザー |
|
提出日時 | 2015-02-01 23:30:38 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 418 bytes |
コンパイル時間 | 688 ms |
コンパイル使用メモリ | 59,352 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-23 05:31:33 |
合計ジャッジ時間 | 3,284 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 93 |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int main() { int m, n; cin >> m >> n; int tmp = gcd(m, n); m /= tmp; n /= tmp; int ans = 0; while(n != 1) { if (m > n) { m -= n; } else { swap(m, n); } ans++; } ans += m - 1; cout << ans << endl; return 0; }