結果
| 問題 | 
                            No.1339 循環小数
                             | 
                    
| コンテスト | |
| ユーザー | 
                             どらら
                         | 
                    
| 提出日時 | 2021-01-15 23:27:38 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 51 ms / 2,000 ms | 
| コード長 | 1,216 bytes | 
| コンパイル時間 | 1,740 ms | 
| コンパイル使用メモリ | 173,260 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-26 18:31:48 | 
| 合計ジャッジ時間 | 3,440 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 36 | 
ソースコード
#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;
}
            
            
            
        
            
どらら