結果

問題 No.141 魔法少女コバ
コンテスト
ユーザー rsk0315
提出日時 2019-02-22 15:21:36
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 451 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 201 ms
コンパイル使用メモリ 51,624 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-07 06:59:08
合計ジャッジ時間 2,747 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 93
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <cstdint>
#include <algorithm>

int gcd(int m, int n) {
  while (n) std::swap(m %= n, n);
  return m;
}

int main() {
  int N, M;
  scanf("%d %d", &N, &M);

  int g = gcd(M, N);
  M /= g;
  N /= g;

  int res = 0;
  if (N < M) {
    std::swap(M, N);
    ++res;
  }
  while (N > 1) {
    if (M < N) {
      std::swap(M, N);
      continue;
    }
    res += M/N + 1;
    std::swap(M %= N, N);
  }
  printf("%d\n", res+M-1);
}
0