結果

問題 No.1339 循環小数
ユーザー ocvret_ocvret_
提出日時 2021-01-16 01:00:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 1,476 ms
コンパイル使用メモリ 164,272 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-17 19:35:51
合計ジャッジ時間 3,590 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 30 ms
4,380 KB
testcase_22 AC 33 ms
4,376 KB
testcase_23 AC 32 ms
4,376 KB
testcase_24 AC 30 ms
4,380 KB
testcase_25 AC 33 ms
4,376 KB
testcase_26 AC 33 ms
4,384 KB
testcase_27 AC 32 ms
4,376 KB
testcase_28 AC 33 ms
4,376 KB
testcase_29 AC 28 ms
4,380 KB
testcase_30 AC 30 ms
4,376 KB
testcase_31 AC 70 ms
4,376 KB
testcase_32 AC 72 ms
4,376 KB
testcase_33 AC 33 ms
4,376 KB
testcase_34 AC 14 ms
4,376 KB
testcase_35 AC 65 ms
4,380 KB
testcase_36 AC 32 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007

ll totient(ll n){
  ll res = n;
  for(ll i = 2;i*i <= n;i++){
    if(n%i)continue;
    res /= i;
    res *= (i-1);
    while(n%i == 0)n /= i;
  }
  if(n != 1)res = res/n*(n-1);
  return res;
}
ll modpow(ll n,int r,int mod){
  ll res = 1;
  while(r){
    if(r & 1)res = res*n%mod;
    n = n*n%mod;
    r >>= 1;
  }
  return res;
}

int main(){
  
  int T;
  cin >> T;
  while(T--){
    ll n;
    cin >> n;
    while(n%2 == 0)n /= 2;
    while(n%5 == 0)n /= 5;
    ll res = 1ll*MOD*MOD;
    if(n == 1)res = 1;
    ll p = totient(n);
    for(ll i = 1;i*i <= p;i++){
      if(p%i)continue;
      if(modpow(10,i,n) == 1)res = min(res,i);
      if(modpow(10,p/i,n) == 1)res = min(res,p/i);
    }
    cout << res << "\n";
  }
  

  return 0;
}
0