結果

問題 No.3358 逆数の小数部分
コンテスト
ユーザー a01sa01to
提出日時 2025-11-22 00:24:30
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 804 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,371 ms
コンパイル使用メモリ 275,712 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-11-22 00:24:35
合計ジャッジ時間 5,169 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  ll x = 0, y = 1;
  {
    string s;
    cin >> s;
    bool flg = false;
    for (char c : s) {
      if (c == '.') {
        flg = true;
        continue;
      }
      assert(isdigit(c));
      x = x * 10 + (c - '0');
      if (flg) y *= 10;
    }
    swap(x, y);
  }
  int cnt = 0;
  while (true) {
    cnt++;
    // cerr << format("{}: {}/{}", cnt, x, y);
    x %= y;
    if (x == 0) {
      // cerr << format(" -> {}/{}\n", x, y);
      break;
    }
    ll g = gcd(x, y);
    x /= g, y /= g;
    swap(x, y);
    // cerr << format(" -> {}/{}\n", x, y);
  }
  cout << cnt << '\n';
  return 0;
}
0