結果

問題 No.1339 循環小数
ユーザー どららどらら
提出日時 2021-01-15 22:52:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,468 bytes
コンパイル時間 1,830 ms
コンパイル使用メモリ 182,396 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-26 16:56:25
合計ジャッジ時間 3,157 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 3 WA * 33
権限があれば一括ダウンロードができます

ソースコード

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;

map<ll,ll> factorize(ll x){
  map<ll,ll> ret;
  ll d, q;
  while(x>=4 && x%2==0){ret[2]++; x/=2;}
  d = 3; q = x/d;
  while(q>=d){
    if(x%d==0){ ret[d]++; x=q; }else{ d+=2; }
    q=x/d;
  }
  ret[x]++;
  return ret;
}

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;
}


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;
}


ll calc_for_prime(ll p){
  vector<ll> div = divisor(p-1);
  rep(i,div.size()){
    ll m = div[i];
    ll x = mod_pow(10, m, p);
    if(x == 1) return m;
  }
  return 1;
}

ll gcd(ll a, ll b){return (b==0?a:gcd(b,a%b));}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

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

  map<ll,ll> res = factorize(N);

  ll ret = 1;
  FOR(it,res){
    ll x = it->first;
    //cout << " " << x << " " << calc_for_prime(x) << endl;
    ret = lcm(ret, calc_for_prime(x));
  }

  cout << ret << endl;

}



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

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

0