結果

問題 No.3236 累乗数大好きbot
ユーザー ジュ・ビオレ・グレイス
提出日時 2025-08-11 20:20:48
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 58 ms / 4,000 ms
コード長 885 bytes
コンパイル時間 2,015 ms
コンパイル使用メモリ 86,380 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-12 16:12:30
合計ジャッジ時間 6,602 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio, std.algorithm, std.array, std.conv, std.typecons;

immutable Nmax = 10L^^12;

auto dictionary() {
	bool[ulong][] powers;
	powers.length = 40;
	foreach (n; 3 .. 31) {
		auto a = 2L;
		while (a^^n <= Nmax) {
			powers[n][a^^n] = true;
			a++;
		}
	}
	foreach (n; 31 .. 40) {
		powers[n][2L^^n] = true;
	}
	
	ulong[ulong] result;
	foreach (n, aarray; powers)
		foreach (key, _; aarray)
			result[key] = n;
	return result;
}

bool is_square(ulong N) {
	import std.math;
	auto root = cast(ulong) (cast(double) N).sqrt;
	return root^^2 == N;
}

ulong solve(ulong N, ulong[ulong] dict) {
	if (auto ptr = N in dict)
		return *ptr;
	else if (is_square(N))
		return 2;
	else
		return 1;
}


void main() {
	auto Q = readln[0 .. $-1].to!ulong;
	ulong[] N;
	foreach (q; 0 .. Q) N ~= readln[0 .. $-1].to!ulong;
	
	auto dict = dictionary();
	foreach (n; N) solve(n, dict).writeln;
}
0