結果
| 問題 |
No.141 魔法少女コバ
|
| コンテスト | |
| ユーザー |
mayoko_
|
| 提出日時 | 2015-02-01 23:39:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 906 bytes |
| コンパイル時間 | 621 ms |
| コンパイル使用メモリ | 73,024 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-06-23 05:33:36 |
| 合計ジャッジ時間 | 2,246 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 93 |
ソースコード
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define INF 1000000000
using namespace std;
typedef long long ll;
int main(void) {
ll M, N;
cin >> M >> N;
ll g = __gcd(M, N);
M /= g;
N /= g;
ll num = 0;
while (1) {
if (M == N) {
if (M == 1) break;
cout << -1 << endl;
return 0;
}
if (M > N) {
ll k = M/N;
if (k != 1) {
M -= (k-1)*N;
num += k-1;
}
else {
M -= N;
num++;
}
} else {
swap(M, N);
num++;
}
}
cout << num << endl;
return 0;
}
mayoko_