結果
問題 | No.554 recurrence formula |
ユーザー |
|
提出日時 | 2021-03-28 08:39:59 |
言語 | Kuin (KuinC++ v.2021.9.17) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 1,405 bytes |
コンパイル時間 | 2,554 ms |
コンパイル使用メモリ | 147,844 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-09-16 12:12:02 |
合計ジャッジ時間 | 3,401 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
func main()const mod: int :: 1000000007var n: int :: cui@inputInt()var sumOdd: @ModInt :: (#@ModInt).init(0, mod)var sumEven: @ModInt :: (#@ModInt).init(0, mod)var a: []@ModInt :: #[n + 1]@ModIntdo a[1] :: (#@ModInt).init(1, mod)for i(2, n)if(i % 2 = 0)do sumOdd.add(a[i - 1].val)do a[i] :: ##sumOddelsedo sumEven.add(a[i - 1].val)do a[i] :: ##sumEvenend ifdo a[i].mul(i)end fordo cui@print("\{a[n]}\n")end func; val, mod, a, b: 0 to 2 ^ 31.class ModInt()+var val: intvar mod: int+*func toStr(): []charret "\{me.val}"end func+func init(val: int, mod: int): ModIntdo me.val :: val % moddo me.mod :: modret meend func+func add(a: int): ModIntdo me.val :+ aif(me.val >= me.mod)do me.val :- me.modend ifret meend func+func sub(a: int): ModIntif(me.val < a)do me.val :+ me.modend ifdo me.val :- aret meend func+func mul(a: int): ModIntdo me.val :: me.val * a % me.modret meend func+func div(a: int): ModIntdo me.val :: me.val * me.modPow(a, me.mod - 2) % me.modret meend func+func pow(a: int): ModIntdo me.val :: me.modPow(me.val, a)ret meend funcfunc modPow(a: int, b: int): intif(b = 0)ret 1end ifvar res: int :: me.modPow(a, b / 2)do res :: res * res % me.modif(b % 2 = 1)do res :: res * a % me.modend ifret resend funcend class