結果
問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
ユーザー |
|
提出日時 | 2024-03-05 01:23:39 |
言語 | Julia (2.11.2) |
結果 |
AC
|
実行時間 | 1,631 ms / 2,000 ms |
コード長 | 969 bytes |
コンパイル時間 | 68 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 313,656 KB |
最終ジャッジ日時 | 2024-10-01 17:49:46 |
合計ジャッジ時間 | 26,323 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 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} 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)