結果
| 問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
| コンテスト | |
| ユーザー |
はるお味
|
| 提出日時 | 2024-02-01 20:57:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 658 bytes |
| コンパイル時間 | 1,730 ms |
| コンパイル使用メモリ | 166,312 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-28 10:32:07 |
| 合計ジャッジ時間 | 2,461 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 1 |
ソースコード
#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;
}
はるお味