結果

問題 No.1140 EXPotentiaLLL!
ユーザー shi-moshi-mo
提出日時 2020-10-01 00:32:41
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 834 bytes
コンパイル時間 1,389 ms
コンパイル使用メモリ 142,088 KB
実行使用メモリ 9,660 KB
最終ジャッジ日時 2023-09-04 10:11:45
合計ジャッジ時間 8,443 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 540 ms
8,092 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 37 ms
8,364 KB
testcase_09 AC 38 ms
7,640 KB
testcase_10 AC 37 ms
7,536 KB
testcase_11 WA -
testcase_12 AC 39 ms
8,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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