# 思路

$\sum _{i=1}^{k}{a}_{i}\cdot Fi{b}_{i}^{k+1}=\sum _{i=1}^{k}{t}_{i}\cdot \sum _{j=1}^{k}{a}_{j}\cdot Fi{b}_{j}^{i}$$\sum_{i=1}^k a_i \cdot Fib_i^{k+1}=\sum_{i=1}^k t_i \cdot \sum_{j=1}^k a_j \cdot Fib_j^i$

$=\sum _{i=1}^{k}\sum _{j=1}^{k}{t}_{i}\cdot {a}_{j}\cdot Fi{b}_{j}^{i}=\sum _{j=1}^{k}\sum _{i=1}^{k}{t}_{i}\cdot {a}_{j}\cdot Fi{b}_{j}^{i}=\sum _{j=1}^{k}{a}_{j}\sum _{i=1}^{k}{t}_{i}\cdot Fi{b}_{j}^{i}$$=\sum_{i=1}^k \sum_{j=1}^k t_i \cdot a_j \cdot Fib_j^i=\sum_{j=1}^k \sum_{i=1}^k t_i \cdot a_j \cdot Fib_j^i=\sum_{j=1}^k a_j \sum_{i=1}^k t_i \cdot Fib_j^i$

$=\sum _{i=1}^{k}{a}_{i}\sum _{j=1}^{k}{t}_{j}\cdot Fi{b}_{i}^{j}$$=\sum_{i=1}^k a_i \sum_{j=1}^k t_j \cdot Fib_i^j$

$\sum _{i=1}^{k}{a}_{i}\cdot Fi{b}_{i}^{k+1}=\sum _{i=1}^{k}{a}_{i}\sum _{j=1}^{k}{t}_{j}\cdot Fi{b}_{i}^{j}$$\sum_{i=1}^k a_i \cdot Fib_i^{k+1}=\sum_{i=1}^k a_i \sum_{j=1}^k t_j \cdot Fib_i^j$

$\mathrm{\forall }i:{a}_{i}\cdot Fi{b}_{i}^{k+1}={a}_{i}\sum _{j=1}^{k}{t}_{j}\cdot Fi{b}_{i}^{j}$$\forall i: a_i \cdot Fib_i^{k+1}=a_i \sum_{j=1}^k t_j \cdot Fib_i^j$为上式的充分条件。

$\mathrm{\forall }i:{a}_{i}\cdot Fi{b}_{i}^{k+1}={a}_{i}\sum _{j=1}^{k}{t}_{j}\cdot Fi{b}_{i}^{j}⇔\mathrm{\forall }i:Fi{b}_{i}^{k+1}=\sum _{j=1}^{k}{t}_{j}\cdot Fi{b}_{i}^{j}$$\forall i: a_i \cdot Fib_i^{k+1}=a_i \sum_{j=1}^k t_j \cdot Fib_i^j \Leftrightarrow \forall i: Fib_i^{k+1} = \sum_{j=1}^k t_j\cdot Fib_i^j$

$\mathrm{\forall }i:Fi{b}_{i}^{k+1}=\sum _{j=1}^{k}{t}_{j}\cdot Fi{b}_{i}^{j}⇔\mathrm{\forall }i:-Fi{b}_{i}^{k+1}+\sum _{j=1}^{k}{t}_{j}\cdot Fi{b}_{i}^{j}=0$$\forall i: Fib_i^{k+1} = \sum_{j=1}^k t_j\cdot Fib_i^j \Leftrightarrow \forall i: -Fib_i^{k+1}+ \sum_{j=1}^k t_j\cdot Fib_i^j=0$

$\mathrm{\forall }i\in \left\{1,2,..,k\right\}:f\left(Fi{b}_{i}\right)=0$$\forall i \in \{1,2,..,k\}:f(Fib_i)=0$,

# 代码

#include <cstdio>
#include <cstring>
typedef long long LLint;
const int maxn=4000+5;

struct vec{
int len; LLint a[maxn];
void set(int a0,int a1){
a[0]=a0;a[1]=a1;len=2;
}
void outp(){
printf("{ ");
for(int i=0;i<len-1;i++){
printf("%lld, ",a[i]);
}
printf("%lld } ",a[len-1]);
}
};

void mul(const vec& a,const vec& b,vec& c,LLint M){
c.len=a.len+b.len-1;
memset(c.a,0x00,sizeof(LLint)*(c.len+1));
for(int i=0;i<a.len;i++){
for(int j=0;j<b.len;j++){
c.a[i+j] = (c.a[i+j] + a.a[i]*b.a[j]%M)%M;
}
}
}

void copy(const vec& a,vec& b){
b.len=a.len;
memcpy(b.a,a.a,sizeof(LLint)*(a.len+1));
}

int M;
void operator *=(vec& a,const vec& b){
vec c; mul(a,b,c,M); copy(c,a);
}

LLint fib[maxn]; vec base,step;

int main(){
freopen("num.in","r",stdin);
freopen("num.out","w",stdout);
int k; scanf("%d%lld",&k,&M);
fib[0]=fib[1]=1;
for(int i=2; i<=k+1; i++){
fib[i] = (fib[i-1] + fib[i-2]) %M;
}
base.len=base.a[0]=1;
for(int i=1; i<=k; i++){
step.set(-fib[i],1);
base *= step;
}
LLint sum=0;
for(int i=1;i<=k;i++){
int p; scanf("%d",&p);
sum = ((sum - base.a[i-1]*p % M)%M + M) %M;
}
printf("%lld\n",sum);
return 0;
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120