結果

問題 No.1339 循環小数
ユーザー 👑 NachiaNachia
提出日時 2021-01-15 22:07:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 425 ms / 2,000 ms
コード長 645 bytes
コンパイル時間 1,901 ms
コンパイル使用メモリ 207,672 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-04 23:57:22
合計ジャッジ時間 8,976 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 5 ms
6,812 KB
testcase_02 AC 5 ms
6,816 KB
testcase_03 AC 4 ms
6,812 KB
testcase_04 AC 4 ms
6,940 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 5 ms
6,944 KB
testcase_10 AC 5 ms
6,944 KB
testcase_11 AC 58 ms
6,944 KB
testcase_12 AC 63 ms
6,940 KB
testcase_13 AC 52 ms
6,944 KB
testcase_14 AC 56 ms
6,940 KB
testcase_15 AC 55 ms
6,940 KB
testcase_16 AC 47 ms
6,940 KB
testcase_17 AC 60 ms
6,940 KB
testcase_18 AC 47 ms
6,944 KB
testcase_19 AC 50 ms
6,944 KB
testcase_20 AC 46 ms
6,940 KB
testcase_21 AC 350 ms
6,940 KB
testcase_22 AC 343 ms
6,944 KB
testcase_23 AC 352 ms
6,944 KB
testcase_24 AC 339 ms
6,944 KB
testcase_25 AC 343 ms
6,944 KB
testcase_26 AC 344 ms
6,944 KB
testcase_27 AC 357 ms
6,940 KB
testcase_28 AC 353 ms
6,944 KB
testcase_29 AC 325 ms
6,940 KB
testcase_30 AC 336 ms
6,944 KB
testcase_31 AC 362 ms
6,940 KB
testcase_32 AC 359 ms
6,944 KB
testcase_33 AC 331 ms
6,944 KB
testcase_34 AC 353 ms
6,940 KB
testcase_35 AC 425 ms
6,944 KB
testcase_36 AC 327 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

ULL loop(ULL N){
  while(N%2==0) N/=2;
  while(N%5==0) N/=5;
  if(N==1) return 1;
	unordered_map<ULL,ULL> X(30000);
  ULL p=1;
  rep(i,30000){ X[p]=i; p=p*10%N; if(p==1) return i+1; }
  p=1;
  ULL inv=0; for(ULL i=1; i<10; i++) if(N*i%10==9) inv=(N*i+1)/10;
  ULL q=1; rep(i,30000) q=q*inv%N;
  rep(i,40000){ p=p*q%N; if(X.count(p)) return (i+1)*30000+X[p]; }
  return ~0ull;
}

int main(){
  int T; scanf("%d",&T);
  while(T--){
    ULL N; scanf("%llu",&N);
    printf("%llu\n",loop(N));
  }
  return 0;
}
0