結果

問題 No.1339 循環小数
ユーザー chocoruskchocorusk
提出日時 2021-01-15 21:41:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,616 bytes
コンパイル時間 1,270 ms
コンパイル使用メモリ 134,544 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-17 16:28:40
合計ジャッジ時間 3,322 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 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,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 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,384 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 29 ms
4,376 KB
testcase_22 AC 32 ms
4,376 KB
testcase_23 AC 31 ms
4,380 KB
testcase_24 AC 28 ms
4,376 KB
testcase_25 AC 32 ms
4,380 KB
testcase_26 AC 32 ms
4,380 KB
testcase_27 AC 31 ms
4,376 KB
testcase_28 AC 32 ms
4,380 KB
testcase_29 AC 27 ms
4,376 KB
testcase_30 AC 28 ms
4,376 KB
testcase_31 AC 70 ms
4,380 KB
testcase_32 AC 73 ms
4,376 KB
testcase_33 AC 32 ms
4,376 KB
testcase_34 AC 13 ms
4,376 KB
testcase_35 AC 65 ms
4,376 KB
testcase_36 AC 31 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll powmod(ll a, ll k, ll MOD){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
int main()
{
    int t; cin>>t;
    while(t--){
        ll n; cin>>n;
        while(n%2==0) n/=2;
        while(n%5==0) n/=5;
        if(n==1){
            cout<<1<<endl;
            continue;
        }
        ll phi=n;
        ll n1=n;
        for(int i=2; i*i<=n1; i++){
            if(n1%i==0){
                phi/=i;
                phi*=(i-1);
                while(n1%i==0) n1/=i;
            }
        }
        if(n1>1){
            phi/=n1;
            phi*=(n1-1);
        }
        vector<ll> v;
        for(int i=1; i*i<=phi; i++){
            if(phi%i==0){
                v.push_back(i);
                if(i*i<phi) v.push_back(phi/i);
            }
        }
        sort(v.begin(), v.end());
        for(auto x:v){
            if(powmod(10, x, n)==1){
                cout<<x<<endl;
                break;
            }
        }
    }
    return 0;
}
0