啥也不会,先传板子
可AC POJ3070
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define FAST ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (int)1e4;
const int maxn = 2;
using namespace std;
struct Matrix
{
int mat[maxn][maxn];
Matrix() {}
Matrix operator*(Matrix const &b)const
{
Matrix res;
memset(res.mat, 0, sizeof(res.mat));
for (int i = 0 ;i < maxn; i++)
for (int j = 0; j < maxn; j++)
for (int k = 0; k < maxn; k++)
res.mat[i][j] = (res.mat[i][j]+this->mat[i][k] * b.mat[k][j])%mod;
return res;
}
};
Matrix pow_mod(Matrix base, int n)
{
Matrix res;
memset(res.mat, 0, sizeof(res.mat));
for (int i = 0; i < maxn; i++)
res.mat[i][i] = 1;
while (n > 0)
{
if (n & 1) res = res*base;
base = base*base;
n >>= 1;
}
return res;
}
int main()
{
Matrix base;
for(int i = 0; i < maxn; i++){
for(int j = 0; j < maxn; j++){
base.mat[i][j] = 1;
}
}
base.mat[1][1] = 0;
int n;
while(~scanf("%d", &n) && (n + 1)){
Matrix ans = pow_mod(base, n);
printf("%d\n", ans.mat[0][1]);
}
return 0;
}