http://poj.org/problem?id=3070
有点水呀
#include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <set> using namespace std; const int N=3000; const int M=10000; int a1,a2,b1,b2; int A1,A2,B1,B2; void func1() { int tempa1,tempa2; int tempb1,tempb2; tempa1=a1*A1+a2*B1; tempa2=a1*A2+a2*B2; tempb1=b1*A1+b2*B1; tempb2=b1*A2+b2*B2; a1=tempa1%M; a2=tempa2%M; b1=tempb1%M; b2=tempb2%M; } void func2() { int tempa1,tempa2; int tempb1,tempb2; tempa1=A1*A1+A2*B1; tempa2=A1*A2+A2*B2; tempb1=B1*A1+B2*B1; tempb2=B1*A2+B2*B2; A1=tempa1%M; A2=tempa2%M; B1=tempb1%M; B2=tempb2%M; } int main() { //freopen("data.txt","r",stdin); int n; while(scanf("%d",&n)!=EOF) { //cout<<n<<endl; if(n==-1) break; if(n==0) { printf("0\n"); continue; } a1=1;a2=1;b1=1;b2=0; A1=1;A2=1;B1=1;B2=0; --n; while(n) { if(n&1) func1(); func2(); n=n>>1; } printf("%d\n",a2); } return 0; }