赞
踩
- typedef long long ll;
-
- ll mod_pow(ll x, ll n, ll mod)
- {
- ll res = 1;
- while(n > 0){
- if(n & 1)
- res = res * x %mod;
- //如果二进制的最低位为1,就要乘上x^(2^i)
- x = x * x % mod;
- n >>= 1;
- }
- return res;
- }
- #include <cstdio>
- #include <cstring>
- #include <cstdlib>
- #include <vector>
-
- using namespace std;
-
- typedef vector<int> vec;
- typedef vector<vec> mat;
- typedef long long ll;
-
- const int M = 10000;
-
- //计算两个矩阵的积
- mat mul(mat &A, mat &B)
- {
- mat C(A.size(), vec(B[0].size()));
- for(int i=0;i< A.size(); i++)
- {
- for(int k=0;k<B.size();k++)
- {
- for(int j=0;j<B[0].size();j++)
- {
- C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
- }
- }
- }
- return C;
- }
-
- //计算A^n
- mat pow(mat A, ll n)
- {
- mat B(A.size(), vec(A.size()));
- for(int i=0;i<A.size();i++)
- {
- B[i][i] = 1;
- }
- while(n > 0)
- {
- if(n&1)
- B = mul(B, A);
- A = mul(A, A);
- n >>= 1;
- }
- return B;
- }
-
- ll n;
-
- int main()
- {
- scanf("%lld",&n);
- mat A(2, vec(2));
- A[0][0] = 1;
- A[0][1] = 1;
- A[1][0] = 1;
- A[1][1] = 0;
- A = pow(A, n);
- printf("%d\n", A[1][0]);
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。