結果

問題 No.3358 逆数の小数部分
コンテスト
ユーザー SnowBeenDiding
提出日時 2025-11-14 23:01:06
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,054 bytes
コンパイル時間 4,814 ms
コンパイル使用メモリ 335,120 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-11-14 23:01:23
合計ジャッジ時間 6,029 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
using namespace atcoder;
using namespace std;

typedef long long ll;

int ans;

__int128 mygcd(__int128 a, __int128 b) {
    ans++;
    if (a == b) return 0;
    if (b == 0) {
        return a;
    } else {
        return mygcd(b, a % b);
    }
}

__int128 f(int k) {
    __int128 x = 1;
    rep(i, 0, k) x *= 10;
    return x;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(12);
    ans = 0;
    __int128 a, b;
    ll na, nb;
    char c;
    cin >> na >> c;
    int sz = 0;
    if (c == '.') {
        string s;
        cin >> s;
        sz = s.size();
        nb = stoll(s);
    } else {
        nb = 0;
    }
    a = na;
    b = nb;
    a *= f(sz);
    a += b;
    b = f(sz);
    cerr << (ll)a << '/' << (ll)b << endl;
    while (!(a == 0 || b == 0)) {
        ans++;
        swap(a, b);
        a %= b;
        cerr << (ll)a << '/' << (ll)b << endl;
    }
    cout << ans << endl;
}
0