結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー バカらっくバカらっく
提出日時 2018-03-06 11:06:07
言語 Swift
(5.10.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 247 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 127,808 KB
実行使用メモリ 8,004 KB
最終ジャッジ日時 2023-08-20 10:34:33
合計ジャッジ時間 2,246 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,880 KB
testcase_01 AC 3 ms
7,848 KB
testcase_02 AC 4 ms
8,004 KB
testcase_03 AC 3 ms
7,888 KB
testcase_04 AC 4 ms
7,928 KB
testcase_05 AC 4 ms
7,880 KB
testcase_06 AC 3 ms
7,928 KB
testcase_07 AC 4 ms
7,872 KB
testcase_08 AC 4 ms
7,944 KB
testcase_09 AC 5 ms
7,880 KB
testcase_10 AC 14 ms
7,856 KB
testcase_11 AC 57 ms
7,868 KB
testcase_12 AC 57 ms
7,864 KB
testcase_13 AC 58 ms
7,880 KB
testcase_14 AC 57 ms
7,720 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.swift:9:5: warning: immutable value 'i' was never used; consider replacing with '_' or removing it
for i in 3...step {
    ^
    _

ソースコード

diff #

let inpt = readLine()!.split(separator: " ").map({Int($0)!})

let step = inpt[0]
let mod = inpt[1]

var prev2 = 0
var prev1 = 1

for i in 3...step {
    var num = prev2 + prev1
    num = num % mod
    prev2 = prev1
    prev1 = num
}

print(prev1)
0