結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー otamay6otamay6
提出日時 2024-03-05 21:19:37
言語 Julia
(1.10.2)
結果
RE  
実行時間 -
コード長 995 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 7,200 KB
実行使用メモリ 473,224 KB
最終ジャッジ日時 2024-04-09 14:37:44
合計ジャッジ時間 31,911 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0