結果
問題 | No.141 魔法少女コバ |
ユーザー |
|
提出日時 | 2016-02-17 13:06:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 865 bytes |
コンパイル時間 | 1,344 ms |
コンパイル使用メモリ | 158,096 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 07:27:23 |
合計ジャッジ時間 | 3,342 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 93 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #ifdef __unix__ #include <bits/stdc++.h> #else #include "bits\stdc++.h" #endif #include <functional> #include <vector> #include <set> #include <string> #include <queue> #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; int gcd ( int a, int b ) { int c; while ( a != 0 ) { c = a; a = b%a; b = c; } return b; } int main() { cin.tie(0); ios::sync_with_stdio(false); int i,j,k; int cnt = 0; int M,N; cin >> M >> N; int a = gcd(M,N); M /= a; N /= a; if(M < N) { swap(M,N); cnt++; } // M >= N while(1) { int a = M/N; if(M%N == 0) a--; cnt += a; M -= a*N; if(M == N) break; swap(M,N); cnt++; } cout << cnt << endl; }