結果

問題 No.1339 循環小数
ユーザー kappybarkappybar
提出日時 2021-01-16 16:37:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,309 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 165,060 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 14:17:05
合計ジャッジ時間 3,738 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 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 3 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 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,376 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 30 ms
4,376 KB
testcase_22 AC 32 ms
4,376 KB
testcase_23 AC 32 ms
4,380 KB
testcase_24 AC 29 ms
4,376 KB
testcase_25 AC 34 ms
4,380 KB
testcase_26 AC 32 ms
4,376 KB
testcase_27 AC 32 ms
4,380 KB
testcase_28 AC 32 ms
4,380 KB
testcase_29 AC 28 ms
4,376 KB
testcase_30 AC 30 ms
4,376 KB
testcase_31 AC 70 ms
4,380 KB
testcase_32 AC 70 ms
4,376 KB
testcase_33 AC 32 ms
4,380 KB
testcase_34 AC 14 ms
4,376 KB
testcase_35 AC 64 ms
4,376 KB
testcase_36 AC 32 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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;

long long phi(long long n){
    long long res = n;
    for(long long i=2;i*i<=n;i++){
        if(n%i==0){
            res /= i;
            res *= i-1;
            while(n%i==0) n/=i;
        }
    }
    if(n > 1){
        res /= n;
        res *= n-1;
    }
    return res;
}

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

void solve(){
    ll n;
    cin >> n;
    while(n%2==0) n /= 2;
    while(n%5==0) n /= 5;
    ll p = phi(n);
    ll ans = p;
    for(ll i=1;i*i<=p;i++){
        if(p%i==0){
            if(modpow(10,i,n) == 1) chmin(ans,i);
            if(modpow(10,p/i,n) == 1) chmin(ans,p/i);
        }
    }
    cout << ans << endl;
    return;
}

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