結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー はるお味はるお味
提出日時 2024-02-01 20:57:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 658 bytes
コンパイル時間 1,910 ms
コンパイル使用メモリ 167,388 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-01 20:57:31
合計ジャッジ時間 2,855 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<VL> VVL;
typedef long long LL;

int n,m;

int f(int i,int j){return i*2+j;}

void g(LL A[],LL B[],LL C[]){
  LL kk[4]={};
  rep(i,2){
    rep(j,2){
      rep(k,2){
        kk[f(i,j)]+=A[f(i,k)]*B[f(k,j)];
      }
    }
  }
  rep(i,4){C[i]=kk[i]%m;}
}


int main() {
  cin>>n>>m;
  LL A[4]={2,1,1,1},ans[4]={1,0,0,1};
  int k=n/2;
  while(k!=0){
    if(k%2==1){g(ans,A,ans);}
    g(A,A,A);
    k/=2;
  }
  LL aaa=ans[0];
  if(n%2==0){aaa=ans[3];}
  cout<<aaa<<endl;
}
0