原题略,主要考察的是矩阵快速幂的做法,直接输出结果就好,灰常适合做模板!遂记录之!
#include <stdio.h>
#include <math.h>
#include <vector>
#include <queue>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define Mod 10000
using namespace std;
int res[5][5];
int mat[5][5];
void Matmul(int x[5][5],int y[5][5])
{
int t[5][5]={0};
for(int i=0;i<2;i++){
for(int k=0;k<2;k++){
if(x[i][k]){
for(int j=0;j<2;j++)
t[i][j]=(t[i][j]+(x[i][k]*y[k][j]))%Mod;
}
}
}
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
x[i][j]=t[i][j];
}
}
}
void Matrix(int x[5][5],int n)
{
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
res[i][j]=(i==j);
}
}
while(n){
if(n&1)Matmul(res,x);
Matmul(x,x);
n>>=1;
}
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
mat[0][0]=mat[0][1]=mat[1][0]=1;
mat[1][1]=0;
if(n==-1)break;
if(n==0){
printf("0\n");
continue;
}
Matrix(mat,n);
printf("%d\n",res[0][1]);
}
return 0;
}