結果
| 問題 |
No.1339 循環小数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-30 10:21:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 1,235 bytes |
| コンパイル時間 | 2,475 ms |
| コンパイル使用メモリ | 198,916 KB |
| 最終ジャッジ日時 | 2025-01-18 09:52:14 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
template<typename T>
T euler_phi(T n){
T res=n;
for(T i=2;i*i<=n;++i){
if(n%i==0){
res-=res/i;
while(n%i==0)n/=i;
}
}
if(n>1)res-=res/n;
return res;
}
template<typename T> vector<T> divisor(T n){
vector<T> res;
for(T i=1;i*i<=n;++i){
if(n%i==0){
res.emplace_back(i);
if(i!=n/i)res.emplace_back(n/i);
}
}
sort(res.begin(), res.end());
return res;
}
ll mod_pow(ll x,ll n,ll Mod){
x%=Mod;
ll res=1;
while(n>0){
if(n&1LL)res=res*x%Mod;
x=x*x%Mod; n>>=1LL;
}
return res;
}
int solve(int n){
while(n%2==0)n/=2;
while(n%5==0)n/=5;
int res=n;
for(int d:divisor(euler_phi(n))){
if(mod_pow(10,d,n)==1){
res=d; break;
}
}
return res;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int q; cin >> q;
while(q--){
int n; cin >> n;
cout << solve(n) << "\n";
}
}