結果

問題 No.1339 循環小数
ユーザー Example0911Example0911
提出日時 2021-02-01 18:48:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,191 bytes
コンパイル時間 2,152 ms
コンパイル使用メモリ 208,868 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-12 10:17:51
合計ジャッジ時間 6,781 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
}
ll beki[10010];
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;
		}
		ll now = 1;
		for (int i = 0; i < 2010; i++) {
			beki[i] = now;
			now *= 10; now %= 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 (beki[p] == 1) {
				cout << p << endl; break;
			}
		}
	}
	return 0;
}
0