結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー 37zigen37zigen
提出日時 2018-04-21 07:55:06
言語 Fortran
(gFortran 13.2.0)
結果
AC  
実行時間 368 ms / 2,000 ms
コード長 479 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 26,124 KB
実行使用メモリ 315,004 KB
最終ジャッジ日時 2023-09-09 12:17:30
合計ジャッジ時間 2,789 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
80,644 KB
testcase_01 AC 31 ms
80,604 KB
testcase_02 AC 28 ms
80,612 KB
testcase_03 AC 28 ms
80,624 KB
testcase_04 AC 28 ms
80,748 KB
testcase_05 AC 28 ms
80,640 KB
testcase_06 AC 27 ms
80,808 KB
testcase_07 AC 28 ms
80,656 KB
testcase_08 AC 29 ms
81,096 KB
testcase_09 AC 38 ms
85,292 KB
testcase_10 AC 92 ms
127,496 KB
testcase_11 AC 368 ms
314,992 KB
testcase_12 AC 308 ms
315,004 KB
testcase_13 AC 286 ms
314,988 KB
testcase_14 AC 282 ms
315,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

module mdl
    integer*8::f(10000000)
contains
    recursive function fib(n,m)result(res)
        integer*8::n,m,res
        if(f(n)/=-1)then
            res=f(n)
        else
            res=mod(fib(n-1,m)+fib(n-2,m),m)
            f(n)=res
        end if
    end function
end module


program main
    use mdl
    implicit none
    integer*8::i,j,k,n,m
    read(*,*)n,m
    f(1)=0
    f(2)=mod(1,m)
    do i=3,size(f)
        f(i)=-1
    end do
    print*,fib(n,m)
end program
0