結果
問題 | No.2481 Shiritori |
ユーザー |
|
提出日時 | 2023-09-22 22:39:19 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,113 bytes |
コンパイル時間 | 3,918 ms |
コンパイル使用メモリ | 171,696 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-08 13:23:21 |
合計ジャッジ時間 | 5,115 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
ソースコード
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) {if (M <= 2) {writeln("First");} else {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) {// assertionassert(0 <= x);assert(1 <= MOD);// normalizea %= MOD; a += MOD; a %= MOD;// simple caseif (MOD == 1) {return 0L;}if (x == 0) {return 1L;}if (x == 1) {return a;}// calculatelong 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;}