結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー arbtarbt
提出日時 2017-09-26 21:44:11
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 444 ms / 2,000 ms
コード長 491 bytes
コンパイル時間 10,292 ms
コンパイル使用メモリ 429,520 KB
実行使用メモリ 55,416 KB
最終ジャッジ日時 2024-04-30 16:15:12
合計ジャッジ時間 16,666 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 329 ms
55,368 KB
testcase_01 AC 324 ms
55,116 KB
testcase_02 AC 328 ms
55,204 KB
testcase_03 AC 323 ms
55,284 KB
testcase_04 AC 321 ms
55,336 KB
testcase_05 AC 330 ms
55,120 KB
testcase_06 AC 326 ms
55,168 KB
testcase_07 AC 323 ms
55,380 KB
testcase_08 AC 330 ms
55,276 KB
testcase_09 AC 333 ms
55,232 KB
testcase_10 AC 353 ms
55,240 KB
testcase_11 AC 440 ms
55,244 KB
testcase_12 AC 432 ms
55,260 KB
testcase_13 AC 441 ms
55,224 KB
testcase_14 AC 444 ms
55,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:29:11: warning: parameter 'argv' is never used
fun main( argv : Array<String> ) {
          ^

ソースコード

diff #

import java.util.Scanner

//
fun _Do() {
    

    val N = scan.nextLong()
    val M = scan.nextLong()
    
    println(when(N){
        1L -> 0L
        2L -> 1L
        else -> {
            var f1 = 0L
            var f2 = 1L
            var f=1L
            for (i in 3..N) {
                f = (f1+f2) % M
                f1 = f2 % M
                f2 = f
            }
            f
        }
    })
}

var scan = Scanner(System.`in`)
fun main( argv : Array<String> ) {
    _Do()
}
0