結果

問題 No.1339 循環小数
ユーザー yuji9511yuji9511
提出日時 2021-01-15 22:45:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,237 bytes
コンパイル時間 2,437 ms
コンパイル使用メモリ 214,780 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-17 18:03:05
合計ジャッジ時間 4,113 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;}
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
vector<ll> factor(ll M){
    vector<ll> fac;
    if(M == 1){
        fac.push_back(1); return fac;
    }
    for(ll i = 2; i*i <= M; i++){
        while(M % i == 0){
            fac.push_back(i); M /= i;
        }
    }
    if(M != 1) fac.push_back(M);
    sort(fac.begin(), fac.end());
    return fac;
}

vector<ll> divisor(ll M){
    vector<ll> div;
    for(ll i = 1; i * i <= M; i++){
        if(M % i == 0){
            div.push_back(i); if(i * i != M) div.push_back(M / i);
        }
    }
    sort(div.begin(), div.end());
    return div;
}

ll power(ll x, ll n, ll m = MOD){
    if(n == 0) return 1LL;
    ll res = power(x * x % m, n/2, m);
    if(n % 2 == 1) (res *= x) %= m;
    return res;
}



void solve(){
    ll N;
    cin >> N;
    ll M = N;
    while(M % 2 == 0) M /= 2;
    while(M % 5 == 0) M /= 5;
    if(M == 1){
        print(1);
        return;
    }
    auto dd = factor(M);

    map<ll,ll> mp;
    for(auto &e: dd) mp[e]++;
    ll r2 = 1;
    for(auto &e: mp){
        if(e.second > 1){
            rep(i,0,e.second-1){
                r2 *= e.first;
            }
        }
    }

    vll v;
    dd.erase(unique(dd.begin(), dd.end()), dd.end());
    for(auto &e: dd){
        vll d2 = divisor(e-1);
        for(auto &f: d2){
            if(power(10,f,e) == 1){
                v.push_back(f);
                break;
            }
        }
    }
    ll lcms = 0;
    for(auto &e: v){
        lcms = max(lcms, e);
    }
    ll ans = lcms * r2;
    print(ans);
}

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