結果
問題 |
No.1140 EXPotentiaLLL!
|
ユーザー |
|
提出日時 | 2020-10-01 00:32:41 |
言語 | D (dmd 2.109.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 834 bytes |
コンパイル時間 | 1,621 ms |
コンパイル使用メモリ | 141,140 KB |
実行使用メモリ | 8,920 KB |
最終ジャッジ日時 | 2024-06-22 09:13:38 |
合計ジャッジ時間 | 9,331 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 4 WA * 8 |
ソースコード
import std.stdio; import std.algorithm; import std.array; import std.math; bool[] notPrime; void main() { uint t; readf("%s\n", &t); const int PMAX = 5000000; notPrime = generateNotPrime(PMAX); foreach(i; 0..t) { ulong a; uint p; readf("%s %s\n", &a, &p); if (notPrime[p]) { writeln("-1"); continue; } a %= p; for (uint j = p; 1 < j; j--) { if (0 == a) break; a = pow(a, j) % p; } writeln(a); } } bool[] generateNotPrime(uint n) { bool[] notPrime = []; notPrime.length = n + 1; notPrime[1] = true; foreach (i; 2..(n+1)) { if (notPrime[i]) { continue; } for (uint j = i*2; j <= n; j += i) { notPrime[j] = true; } } return notPrime; }