結果

問題 No.1339 循環小数
ユーザー sapphire__15sapphire__15
提出日時 2021-01-16 00:28:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 2,298 bytes
コンパイル時間 1,067 ms
コンパイル使用メモリ 114,380 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-17 19:24:42
合計ジャッジ時間 10,491 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,376 KB
testcase_01 AC 212 ms
4,380 KB
testcase_02 AC 213 ms
4,380 KB
testcase_03 AC 214 ms
4,380 KB
testcase_04 AC 213 ms
4,380 KB
testcase_05 AC 213 ms
4,376 KB
testcase_06 AC 213 ms
4,380 KB
testcase_07 AC 213 ms
4,380 KB
testcase_08 AC 212 ms
4,384 KB
testcase_09 AC 213 ms
4,376 KB
testcase_10 AC 212 ms
4,376 KB
testcase_11 AC 212 ms
4,376 KB
testcase_12 AC 213 ms
4,380 KB
testcase_13 AC 213 ms
4,380 KB
testcase_14 AC 213 ms
4,380 KB
testcase_15 AC 213 ms
4,380 KB
testcase_16 AC 213 ms
4,380 KB
testcase_17 AC 214 ms
4,376 KB
testcase_18 AC 213 ms
4,376 KB
testcase_19 AC 213 ms
4,376 KB
testcase_20 AC 213 ms
4,376 KB
testcase_21 AC 221 ms
4,380 KB
testcase_22 AC 219 ms
4,380 KB
testcase_23 AC 219 ms
4,380 KB
testcase_24 AC 219 ms
4,380 KB
testcase_25 AC 218 ms
4,380 KB
testcase_26 AC 218 ms
4,376 KB
testcase_27 AC 220 ms
4,380 KB
testcase_28 AC 220 ms
4,376 KB
testcase_29 AC 219 ms
4,380 KB
testcase_30 AC 218 ms
4,380 KB
testcase_31 AC 218 ms
4,376 KB
testcase_32 AC 219 ms
4,380 KB
testcase_33 AC 220 ms
4,380 KB
testcase_34 AC 214 ms
4,376 KB
testcase_35 AC 213 ms
4,380 KB
testcase_36 AC 220 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>

typedef int64_t ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, _s) for (int i = (_s);i < (int)( n ); i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &_l, const T b) {
    if (_l < b) {
        _l = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &_l, const T b) {
    if (_l > b) {
        _l = b;
        return true;
    }
    return false;
}

# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

using namespace std;

ll modpow(ll x, ll k, ll p) {
    ll ret = 1;
    while(k) {
        if(k&1) ret = ret*x%p;
        x = x*x%p;
        k >>= 1;
    }
    return ret;
}

ll solve() {
    ll n; cin >> n;
    while(n%2 == 0) n /= 2;
    while(n%5 == 0) n /= 5;
    if(n == 0) return 1;
    ll ans = n;
    auto m = n;
    rip(i, 100000, 2) {
        if(n%i == 0) {
            while(n%i == 0) n /= i;
            ans /= i;
            ans *= i-1;
        }
    }
    if(n != 1) ans = ans/n*(n-1);
    ll ret = ans;
    rip(i, 100000, 1) {
        if(ans%i == 0) {
            if(modpow(10, i, m) == 1) chmin(ret, (ll)i);
            if(modpow(10, ans/i, m) == 1) chmin(ret, ans/i);
        }
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t; cin >> t;
    rip(i,t,0) cout << solve() << endl;;
}
0