結果

問題 No.1339 循環小数
ユーザー moririn2528_cmoririn2528_c
提出日時 2021-01-15 21:37:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 971 ms / 2,000 ms
コード長 2,066 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 108,736 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-04 23:00:35
合計ジャッジ時間 23,541 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,248 KB
testcase_01 AC 275 ms
5,376 KB
testcase_02 AC 277 ms
5,376 KB
testcase_03 AC 277 ms
5,376 KB
testcase_04 AC 270 ms
5,376 KB
testcase_05 AC 276 ms
5,376 KB
testcase_06 AC 277 ms
5,376 KB
testcase_07 AC 275 ms
5,376 KB
testcase_08 AC 283 ms
5,376 KB
testcase_09 AC 283 ms
5,376 KB
testcase_10 AC 284 ms
5,376 KB
testcase_11 AC 361 ms
5,376 KB
testcase_12 AC 379 ms
5,376 KB
testcase_13 AC 348 ms
5,376 KB
testcase_14 AC 354 ms
5,376 KB
testcase_15 AC 360 ms
5,376 KB
testcase_16 AC 354 ms
5,376 KB
testcase_17 AC 368 ms
5,376 KB
testcase_18 AC 344 ms
5,376 KB
testcase_19 AC 350 ms
5,376 KB
testcase_20 AC 350 ms
5,376 KB
testcase_21 AC 894 ms
5,376 KB
testcase_22 AC 925 ms
5,376 KB
testcase_23 AC 887 ms
5,376 KB
testcase_24 AC 882 ms
5,376 KB
testcase_25 AC 912 ms
5,376 KB
testcase_26 AC 909 ms
5,376 KB
testcase_27 AC 918 ms
5,376 KB
testcase_28 AC 917 ms
5,376 KB
testcase_29 AC 885 ms
5,376 KB
testcase_30 AC 906 ms
5,376 KB
testcase_31 AC 971 ms
5,376 KB
testcase_32 AC 958 ms
5,376 KB
testcase_33 AC 879 ms
5,376 KB
testcase_34 AC 951 ms
5,376 KB
testcase_35 AC 968 ms
5,376 KB
testcase_36 AC 882 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
#include<unordered_map>
using namespace std;
typedef long long int LL;
typedef pair<LL,LL> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
    for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
    if(vec_n==-1)vec_n=vec_s.size();
    for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

void init(){
    
}

long long int pow_mod(long long int p_a,long long int p_n,long long int p_p=1e9+7){
    //p_a^p_n mod p_p
    long long int p_b=1,p_t=1;
    for(;p_b<=p_n;p_b<<=1);
    for(p_b>>=1;p_b>0;p_b>>=1){
        p_t*=p_t;
        if(p_t>=p_p)p_t%=p_p;
        if(p_n&p_b)p_t*=p_a;
        if(p_t>=p_p)p_t%=p_p;
    }
    return p_t;
}

const LL N=4e4;

void solve(){
    LL n,m;
    int i,j,k;
    LL a,b,c;
    cin>>n;
    a=pow_mod(10,1e9,n);
    if(a==0){
        cout<<1<<endl;
        return;
    }
    unordered_map<LL,LL> m1;
    b=pow_mod(10,N,n);
    c=a;
    LL s=MAX;
    for(i=0;i<N;i++){
        c=c*b%n;
        if(m1.find(c)==m1.end())m1[c]=(i+1)*N;
        else s=min(s,(i+1)*N-m1[c]);
    }
    for(i=0;i<N;i++,a*=10){
        a%=n;
        if(m1.find(a)!=m1.end()){
            s=min(s,m1[a]-i);
        }
    }
    cout<<s<<endl;
}

int main(){
    int n,i;
    init();
    cin>>n;
    for(i=0;i<n;i++){
        solve();
    }
}
0