結果

問題 No.1339 循環小数
ユーザー Example0911Example0911
提出日時 2021-02-01 18:57:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 2,333 bytes
コンパイル時間 2,165 ms
コンパイル使用メモリ 209,036 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 10:18:16
合計ジャッジ時間 4,349 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 33 ms
4,376 KB
testcase_22 AC 35 ms
4,376 KB
testcase_23 AC 35 ms
4,376 KB
testcase_24 AC 33 ms
4,376 KB
testcase_25 AC 36 ms
4,380 KB
testcase_26 AC 35 ms
4,380 KB
testcase_27 AC 35 ms
4,380 KB
testcase_28 AC 35 ms
4,380 KB
testcase_29 AC 30 ms
4,376 KB
testcase_30 AC 32 ms
4,376 KB
testcase_31 AC 74 ms
4,380 KB
testcase_32 AC 76 ms
4,376 KB
testcase_33 AC 36 ms
4,376 KB
testcase_34 AC 15 ms
4,376 KB
testcase_35 AC 67 ms
4,376 KB
testcase_36 AC 35 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0