結果

問題 No.2481 Shiritori
ユーザー InTheBloomInTheBloom
提出日時 2023-09-22 22:31:49
言語 D
(dmd 2.106.1)
結果
RE  
実行時間 -
コード長 945 bytes
コンパイル時間 4,597 ms
コンパイル使用メモリ 158,032 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-22 22:31:55
合計ジャッジ時間 4,636 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std;

void main () {
    long N, M; readln.read(N, M);

    solve(N, M);
}

void solve (long N, long M) {
    if (modPow(N, M-1, 2) == 0) {
        enforce(0);
        writeln("Second");
    } else {
        writeln("First");
    }
}

void read(T...)(string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}

long modPow (long a, long x, const int MOD) {
    // assertion
    assert(0 <= x);
    assert(1 <= MOD);

    // normalize
    a %= MOD; a += MOD; a %= MOD;

    // simple case
    if (MOD == 1) {
        return 0L;
    }

    if (x == 0) {
        return 1L;
    }

    if (x == 1) {
        return a;
    }

    // calculate
    long res = 1L;
    long base = a % MOD;
    while (x != 0) {
        if ((x&1) != 0) {
            res *= base;
            res %= MOD;
        }
        base = base*base; base %= MOD;
        x >>= 1;
    }

    return res;
}
0