結果

問題 No.2481 Shiritori
コンテスト
ユーザー InTheBloom
提出日時 2023-09-22 22:31:49
言語 D
(dmd 2.109.1)
結果
RE  
実行時間 -
コード長 945 bytes
コンパイル時間 2,904 ms
コンパイル使用メモリ 170,684 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-08 13:16:09
合計ジャッジ時間 4,067 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 RE * 2
other AC * 21 RE * 16
権限があれば一括ダウンロードができます

ソースコード

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