結果

問題 No.1339 循環小数
ユーザー kappybarkappybar
提出日時 2021-01-15 22:30:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,618 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 174,224 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-05 00:31:41
合計ジャッジ時間 3,329 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 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 AC 30 ms
5,376 KB
testcase_32 AC 31 ms
5,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 58 ms
5,376 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y));
#define chmax(x,y) x = max((x),(y));
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

map<ll,ll> memo;

ll gcd(ll i,ll j){
    if(j == 0) return i;
    return gcd(j,i%j);
}

ll lcm(ll i,ll j){
    return i / gcd(i,j) * j;
}


bool finite(ll n){
    while(n%2==0) n/= 2;
    while(n%5==0) n/= 5;
    return (n==1);
}

long long modpow(long long x,long long n) {
    long long ret = 1;
    ll t = 10;
    while (x > 0) {
        if (x & 1) ret = (ret * t) % n;  
        t = (t * t) % n;
        x >>= 1;  
    }
    return ret;
}

ll len(ll p){
    if(memo.count(p) > 0) return memo[p];
    if(p==2 || p==5){
        memo[p] = 1;
        return 1;
    }
    ll q = p-1;
    ll res = p-1;
    for(ll i=1;i*i<=q;i++){
        if(q%i==0){
            if(modpow(i,p) == 1) chmin(res,i);
            if(modpow(q/i,p) == 1) chmin(res,q/i);
        }
    }
    memo[p] = res;
    return res;
}


ll length(ll m){
    ll res = 1;
    for(ll i=2;i*i<=m;i++){
        if(m%i==0){
            res = lcm(res,len(i));
            while(m%i==0) m /= i;
        }
    }
    if(m > 1){
        res = lcm(res,len(m));
    }
    return res;
}


void solve(){
    ll n;
    cin >> n;
    cout << length(n) << endl;
    return;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
0