結果
| 問題 |
No.1339 循環小数
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2021-01-16 02:12:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,194 bytes |
| コンパイル時間 | 1,541 ms |
| コンパイル使用メモリ | 172,936 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-26 20:30:11 |
| 合計ジャッジ時間 | 2,960 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 25 WA * 11 |
ソースコード
#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;
}
}
}
int main(){
int t;
cin >> t;
rep(i,t){
solve();
}
return 0;
}
どらら