結果
問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
ユーザー |
|
提出日時 | 2024-03-05 21:19:37 |
言語 | Julia (2.11.2) |
結果 |
RE
|
実行時間 | - |
コード長 | 995 bytes |
コンパイル時間 | 221 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 468,504 KB |
最終ジャッジ日時 | 2024-10-01 17:50:18 |
合計ジャッジ時間 | 30,364 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 3 |
other | RE * 12 |
ソースコード
module ModIntModule export ModInt,+,-,*,/ struct ModInt{n} <: Integer value::UInt64 ModInt{n}(value::Integer) where{n} = new(mod(value,n)) end import Base: +,-,*,/ +(x::ModInt{n}, y::ModInt{n}) where{n} = ModInt{n}(x.value + y.value); -(x::ModInt{n}, y::ModInt{n}) where{n} = ModInt{n}(n + x.value - y.value); *(x::ModInt{n}, y::ModInt{n}) where{n} = ModInt{n}(x.value * y.value); /(x::ModInt{n}, y::ModInt{n}) where{n} = ModInt{n}(x.value * invmod(y.value, n)); end using .ModIntModule Base.show(io::IO, a::ModInt{n}) where {n} = show(io, a.value) Base.promote_rule(::Type{ModInt{n}}, ::Type{Int}) where {n} = ModInt{n} Base.convert(::Type{ModInt{n}}, x::Int) where {n} = ModInt{n}(x) const modint998244353 = ModInt{998244353} const modint1000000007 = ModInt{1000000007} function main() using Printf n, m = parse.(Int32, split(readline())) a = ModInt{m}.([1 1;1 0]) f = ModInt{m}.([1;0]) f = (a^(n-2))*f @printf(stdout, "%d\n", f[1].value) end main()