結果
| 問題 |
No.978 Fibonacci Convolution Easy
|
| ユーザー |
moririn2528_c
|
| 提出日時 | 2020-01-31 21:52:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 1,307 bytes |
| コンパイル時間 | 775 ms |
| コンパイル使用メモリ | 93,728 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-18 20:55:24 |
| 合計ジャッジ時間 | 1,707 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;
void array_show(int *array,int array_n,char middle=' '){
for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
if(vec_n==-1)vec_n=vec_s.size();
for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
if(vec_n==-1)vec_n=vec_s.size();
for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
int main(){
int n,m;
int i,j,k;
LL a,b,c;
LL s[2]={1,1};
cin>>n>>m;
a=0,b=1;
if(n==1){
cout<<0<<endl;
return 0;
}
for(i=3;i<=n;i++){
swap(a,b);
b+=a*m;
if(b>=MAX)b%=MAX;
s[0]+=b,s[1]+=b*b;
if(s[0]>=MAX)s[0]%=MAX;
if(s[1]>=MAX)s[1]%=MAX;
}
a=s[0]*s[0]+s[1];
if(a%2==1)a+=MAX;
a/=2;
cout<<a%MAX<<endl;
}
moririn2528_c