結果

問題 No.1339 循環小数
ユーザー shinchanshinchan
提出日時 2021-01-16 16:27:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,489 bytes
コンパイル時間 2,853 ms
コンパイル使用メモリ 208,040 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 14:07:10
合計ジャッジ時間 6,243 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
typedef long long ll;
using namespace std;
const ll INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

long long modpow(long long a, long long n, ll mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll euler(map<ll, ll> mp){
    ll ret = 1;
    all(i, mp){
        ret *= i.first - 1;
        ret *= modpow(i.first, i.second - 1, INF);
    }
    return ret;
}

map<ll, ll> pridiv(ll n){
    ll m = n;
    map<ll, ll> mp;
    for(ll i=2;i*i<=m;i++){
        while(n % i == 0){
            n /= i;
            mp[i]++;
        }
    }
    if(n > 1) mp[n]++;
    return mp;
}

vector<ll> divisor(ll n){
    vector<ll> v;
    for(ll i=1;i*i<=n;i++){
        if(n % i == 0){
            if(i * i != n) v.pb(n / i);
            v.pb(i);
        }
    }
    return v;
}

void solve(){
    ll n, ans = INF;
    cin >> n;
    while(n % 2 == 0) n /= 2;
    while(n % 5 == 0) n /= 5;
    all(i, divisor(euler(pridiv(n)))) {
        ll num = modpow(10LL, i, n);
        if(num == 1 || num == 0) ans = min(ans, i);
    }
    cout << ans << endl;
    return;
}

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


0