結果

問題 No.1339 循環小数
ユーザー どららどらら
提出日時 2021-01-16 02:12:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,194 bytes
コンパイル時間 1,675 ms
コンパイル使用メモリ 172,640 KB
実行使用メモリ 4,564 KB
最終ジャッジ日時 2023-08-17 20:19:22
合計ジャッジ時間 3,651 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 27 ms
4,376 KB
testcase_22 AC 29 ms
4,376 KB
testcase_23 AC 28 ms
4,380 KB
testcase_24 AC 27 ms
4,376 KB
testcase_25 AC 29 ms
4,380 KB
testcase_26 AC 29 ms
4,380 KB
testcase_27 AC 29 ms
4,376 KB
testcase_28 AC 29 ms
4,376 KB
testcase_29 AC 25 ms
4,376 KB
testcase_30 AC 26 ms
4,380 KB
testcase_31 AC 50 ms
4,376 KB
testcase_32 AC 51 ms
4,376 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 44 ms
4,376 KB
testcase_36 AC 29 ms
4,564 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;
    }
  }
}

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

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