結果

問題 No.1339 循環小数
ユーザー kawara_y_kyoprokawara_y_kyopro
提出日時 2021-01-16 02:01:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 2,945 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 126,600 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 20:18:32
合計ジャッジ時間 3,788 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 3 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 35 ms
4,380 KB
testcase_22 AC 38 ms
4,380 KB
testcase_23 AC 38 ms
4,380 KB
testcase_24 AC 35 ms
4,380 KB
testcase_25 AC 40 ms
4,376 KB
testcase_26 AC 41 ms
4,380 KB
testcase_27 AC 39 ms
4,376 KB
testcase_28 AC 40 ms
4,380 KB
testcase_29 AC 33 ms
4,376 KB
testcase_30 AC 35 ms
4,376 KB
testcase_31 AC 103 ms
4,380 KB
testcase_32 AC 104 ms
4,376 KB
testcase_33 AC 39 ms
4,380 KB
testcase_34 AC 14 ms
4,380 KB
testcase_35 AC 97 ms
4,376 KB
testcase_36 AC 39 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vii = V<int>;
using vvll = V<vll>;
using vvii = V< V<int> >;
using PII = P<int, int>;
using PLL = P<ll, ll>;
#define RevREP(i,n,a) for(ll i=n;i>a;i--)  // (a,n]
#define REP(i,a,n) for(ll i=a;i<n;i++)  // [a,n)
#define rep(i, n) REP(i,0,n)
#define ALL(v) v.begin(),v.end()
#define eb emplace_back
#define pb push_back
#define sz(v) int(v.size())

template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
template< class A, class B > ostream& operator <<(ostream& out, const P<A, B> &p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template< class A > ostream& operator <<(ostream& out, const V<A> &v) {
    out << '[';
    for (int i=0;i<int(v.size());i++) {
        if (i) out << ", ";
        out << v[i];
    }
    return out << ']';
}

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

ll powmod(ll a, ll p, ll m) {
    if (p == 0) return 1;
    ll tmp = powmod(a, p >> 1, m);
    if (p & 1) return (tmp * tmp % m) * a % m;
    else return tmp * tmp % m;
}

void solve() {
    ll n; cin >> n;
    while (n % 2 == 0) n /= 2;
    while (n % 5 == 0) n /= 5;
    if (n == 1) {
        cout << 1 << '\n';
        return;
    }
    
    ll phi = n, orign = n;
    {
        vii div;
        for (ll i = 2; i * i <= n; i++) {
            if (n % i == 0) div.eb(i);
            while (n % i == 0) n /= i;
        }
        if (n > 1) div.eb(n);

        for (int bit = 1; bit < (1 << sz(div)); bit++) {
            ll mul = 1;
            for (int i = 0; i < sz(div); i++) if (bit >> i & 1) mul *= div[i];
            phi += (__builtin_popcount(bit) & 1 ? -1 : 1) * orign / mul;
        }
    }
    n = orign;

    int ans = INF;
    for (ll i = 1; i * i <= phi; i++) {
        if (phi % i == 0) {
            if (powmod(10, i, n) == 1) chmin(ans, int(i));
            if (powmod(10, phi / i, n) == 1) chmin(ans, int(phi / i));
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin >> t;
    while (t-->0) {
        solve();
    }
    return 0;
}
0