結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー otamay6otamay6
提出日時 2024-03-05 01:16:30
言語 Julia
(1.10.2)
結果
AC  
実行時間 1,637 ms / 2,000 ms
コード長 917 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 6,940 KB
実行使用メモリ 354,372 KB
最終ジャッジ日時 2024-04-09 14:37:08
合計ジャッジ時間 26,595 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,590 ms
303,540 KB
testcase_01 AC 1,609 ms
303,384 KB
testcase_02 AC 1,609 ms
305,440 KB
testcase_03 AC 1,628 ms
302,996 KB
testcase_04 AC 1,587 ms
303,288 KB
testcase_05 AC 1,602 ms
303,272 KB
testcase_06 AC 1,604 ms
303,652 KB
testcase_07 AC 1,579 ms
304,960 KB
testcase_08 AC 1,591 ms
305,496 KB
testcase_09 AC 1,594 ms
303,244 KB
testcase_10 AC 1,597 ms
305,512 KB
testcase_11 AC 1,618 ms
303,544 KB
testcase_12 AC 1,572 ms
354,372 KB
testcase_13 AC 1,637 ms
304,168 KB
testcase_14 AC 1,573 ms
302,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

module ModIntModule
   export ModInt,+,-,*,/
   struct ModInt{n} <: Integer
      k::UInt64
      ModInt{n}(k::Integer) where{n} = new(mod(k,n))
   end

   import Base: +,-,*,/
   +(x::ModInt{n}, y::ModInt{n}) where{n} = ModInt{n}(x.k + y.k);
   -(x::ModInt{n}, y::ModInt{n}) where{n} = ModInt{n}(n + x.k - y.k);
   *(x::ModInt{n}, y::ModInt{n}) where{n} = ModInt{n}(x.k * y.k);
   /(x::ModInt{n}, y::ModInt{n}) where{n} = ModInt{n}(x.k * invmod(y.k, n));

end

using .ModIntModule

Base.show(io::IO, a::ModInt{n}) where {n} = show(io, a.k)
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].k)
0