結果

問題 No.1140 EXPotentiaLLL!
ユーザー shi-moshi-mo
提出日時 2020-10-01 13:39:17
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 589 ms / 2,000 ms
コード長 744 bytes
コンパイル時間 1,455 ms
コンパイル使用メモリ 142,116 KB
実行使用メモリ 9,108 KB
最終ジャッジ日時 2023-09-04 10:12:41
合計ジャッジ時間 8,101 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 585 ms
8,156 KB
testcase_01 AC 534 ms
8,408 KB
testcase_02 AC 579 ms
8,076 KB
testcase_03 AC 395 ms
7,876 KB
testcase_04 AC 310 ms
9,108 KB
testcase_05 AC 478 ms
8,600 KB
testcase_06 AC 457 ms
8,112 KB
testcase_07 AC 589 ms
7,872 KB
testcase_08 AC 38 ms
7,584 KB
testcase_09 AC 38 ms
8,168 KB
testcase_10 AC 39 ms
8,360 KB
testcase_11 AC 39 ms
8,064 KB
testcase_12 AC 38 ms
7,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.algorithm;
import std.array;
import std.math;
import std.numeric;

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;
        }
        writeln((0 != a%p) ? 1 : 0);
    }
}

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