結果
問題 | No.1339 循環小数 |
ユーザー |
![]() |
提出日時 | 2023-09-07 18:31:22 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 998 bytes |
コンパイル時間 | 5,983 ms |
コンパイル使用メモリ | 307,700 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 12:15:50 |
合計ジャッジ時間 | 7,248 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 36 |
ソースコード
#include<bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; using mint=modint998244353; //1000000007; using ll=long long; using pp=pair<ll,ll>; #define sr string #define vc vector #define fi first #define se second #define rep(i,n) for(ll i=0;i<(ll)n;i++) #define pb push_back #define all(v) v.begin(),v.end() #define pque priority_queue #define bpc(a) __builtin_popcount(a) ll mpow(ll a,ll t,ll m){ if(t==0)return 1; ll res=mpow(a,t/2,m); res=res*res%m; if(t&1)res*=a; return res%m; } void sol(){ ll n;cin>>n; while(n%2==0)n/=2; while(n%5==0)n/=5; if(n==1){ cout<<1<<"\n"; return; } ll tor=n,nn=n; for(ll i=2;i*i<=n;i++)if(n%i==0){ while(n%i==0)n/=i; tor-=tor/i; } if(n>1)tor-=tor/n; ll ans=1e9; for(ll i=1;i*i<=tor;i++)if(tor%i==0){ ll r=tor/i; if(mpow(10ll,i,nn)==1)ans=min(ans,i); if(mpow(10ll,r,nn)==1)ans=min(ans,r); } cout<<ans<<"\n"; return; } int main(){ int t;cin>>t; rep(z,t)sol(); }