结合矩阵来写
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
#define mod 10000
struct mat
{
int a[2][2];
};
mat mul(mat a,mat b)
{
mat ret;
memset(ret.a,0,sizeof(ret.a));
for(int i=0;i<2;i++)
{
for(int j=0;j<2;j++)
{
ret.a[i][j] = (a.a[i][0]*b.a[0][j]+a.a[i][1]*b.a[1][j])%mod;
}
}
return ret;
}
mat mpower(mat a,int n)
{
mat I;
I.a[0][0] = I.a[1][1] = 1;
I.a[0][1] = I.a[1][0] = 0;
while(n)
{
if(n&1) I = mul(I,a);
n>>=1;
a = mul(a,a);
}
return I;
}
int main()
{
int n;
while(cin>>n)
{
if(n==-1) break;
mat tmp;
tmp.a[0][0] = tmp.a[0][1] = tmp.a[1][0] = 1;
tmp.a[1][1] = 0;
tmp = mpower(tmp,n);
cout<<tmp.a[1][0]<<endl;
}
return 0;
}