結果
問題 |
No.1161 Many Powers
|
ユーザー |
👑 |
提出日時 | 2020-09-20 09:01:20 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 558 bytes |
コンパイル時間 | 75 ms |
コンパイル使用メモリ | 6,944 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-24 10:39:13 |
合計ジャッジ時間 | 1,519 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 23 |
ソースコード
local mfl, mce = math.floor, math.ceil local a, b, c = io.read("*n", "*n", "*n") if c == 1 then print(0) os.exit() end local function modpow(src) local pow = b local res = 1 while 0 < pow do if pow % 2 == 1 then res = (res * src) % c pow = pow - 1 end src = (src * src) % c pow = mfl(pow / 2) end return res end local t = {1} for i = 2, c - 1 do t[i] = (t[i - 1] + modpow(i)) % c end local mul = mfl(a / c) local rem = a % c local ret = (t[c - 1] * mul) % c if 0 < rem then ret = (ret + t[rem]) % c end print(ret)