結果

問題 No.1339 循環小数
ユーザー どららどらら
提出日時 2021-01-15 23:27:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,216 bytes
コンパイル時間 1,633 ms
コンパイル使用メモリ 171,992 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-17 19:07:49
合計ジャッジ時間 3,534 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<ll> divisor(ll n){
  vector<ll> ret;
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      ret.push_back(i);
      if(i!=n/i) ret.push_back(n/i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

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

ll mod_pow(ll x, ll n, ll mod){
  ll res = 1;
  while(n>0){
    if(n&1) res = res*x%mod;
    x = x*x%mod;
    n >>= 1;
  }
  return res;
}

void solve(){
  ll N;
  cin >> N;

  while(N%2==0) N/=2;
  while(N%5==0) N/=5;
  
  vector<ll> div = divisor(phi(N));
  rep(i,div.size()){
    ll x = div[i];
    if(mod_pow(10, x, N) == 1){
      cout << x << endl;
      return;
    }
  }
  cout << 1 << endl;
}

int main(){
  int t;
  cin >> t;

  rep(i,t){
    solve();
  }
  
  return 0;
}
0