結果
| 問題 |
No.1339 循環小数
|
| コンテスト | |
| ユーザー |
Example0911
|
| 提出日時 | 2021-02-01 18:57:25 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 93 ms / 2,000 ms |
| コード長 | 2,333 bytes |
| コンパイル時間 | 2,016 ms |
| コンパイル使用メモリ | 204,756 KB |
| 最終ジャッジ日時 | 2025-01-18 10:38:21 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 36 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 998244353;
vector<P> prime_factorize(ll N) {
vector<P> res;
for (ll a = 2; a * a <= N; a++) {
if (N % a != 0)continue;
ll ex = 0;
while (N % a == 0) {
ex++; N /= a;
}
res.push_back({ a,ex });
}
if (N != 1)res.push_back({ N, 1 });
return res;
}
vector<ll> enum_divisors(ll N) {
vector<ll> res;
for (ll i = 1; i * i <= N; i++) {
if (N % i == 0) {
res.push_back(i);
if (N / i != i)res.push_back(N / i);
}
}
sort(res.begin(), res.end());
return res;
}
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) :x((x%mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint& operator+=(const mint a) {
if ((x += a.x) >= mod) x -= mod;
return *this;
}
mint& operator-=(const mint a) {
if ((x += mod - a.x) >= mod) x -= mod;
return *this;
}
mint& operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1) a *= *this;
return a;
}
// for prime mod
mint inv() const {
return pow(mod - 2);
}
mint& operator/=(const mint a) {
return (*this) *= a.inv();
}
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
mint POW(mint n, int p) {
if (p == 0)return 1;
if (p % 2 == 0) {
mint t = POW(n, p / 2);
return t * t;
}
return n * POW(n, p - 1);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll T; cin >> T;
for (int _ = 0; _ < T; _++) {
ll N; cin >> N;
while (N % 2 == 0)N /= 2;
while (N % 5 == 0)N /= 5;
if (N == 1) {
cout << 1 << endl; continue;
}
mod = N;
ll phi = N;
for (auto p : prime_factorize(N)) {
phi *= (p.first - 1);
phi /= p.first;
}
vector<ll> a = enum_divisors(phi);
for (auto p : a) {
if (POW(10, p).x == 1) {
cout << p << endl; break;
}
}
}
return 0;
}
Example0911