結果
問題 |
No.1339 循環小数
|
ユーザー |
|
提出日時 | 2021-01-28 19:41:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 1,317 bytes |
コンパイル時間 | 2,110 ms |
コンパイル使用メモリ | 195,940 KB |
最終ジャッジ日時 | 2025-01-18 08:34:00 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; } // オイラーのトーシェント関数 // yukicoder No.1339 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); } } 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=min(res,d); } } 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"; } }