結果
| 問題 |
No.2481 Shiritori
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-09-22 22:11:56 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 925 bytes |
| コンパイル時間 | 4,700 ms |
| コンパイル使用メモリ | 172,692 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-08 12:55:48 |
| 合計ジャッジ時間 | 5,818 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 32 WA * 5 |
ソースコード
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) {
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;
}