結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー monburan_0401monburan_0401
提出日時 2018-10-05 14:56:55
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 754 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 29,568 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 16:44:15
合計ジャッジ時間 960 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
int fibonacci_Number(int n){
    //  フィボナッチ数を求める関数
    //  Fn = Fn-1 + Fn-2
    int i;      //  subscript
    int f[2] = {0,1};
    int next;   //  Fn+1
    for(i = 3; i <= n; i++){
        next = f[0] + f[1];
        //  更新
        f[0] = f[1];
        f[1] = next;
    }
    return next;
}
int main(void){
    int N;          //  Fn の n
    long int M;     //  わる数
    long int Fn;    //  fibonacci number
    long int ans;    //  Fn % M
    
    scanf("%d %ld",&N,&M);

    Fn = fibonacci_Number(N - 1) + fibonacci_Number(N - 2);

    //  check ok
    //  printf("Fn = %ld\n",Fn);

    ans = Fn % M;

    //  check ok
    //  printf("ans = %ld\n",ans);
    printf("%ld\n",ans);

    return 0;
}
0