题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4549
思路:用费马小定理降一下幂,然后就是矩阵快速幂模板了。
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; const ll inff = 0x3f3f3f3f3f3f3f3f; #define FOR(i,a,b) for(int i(a);i<=(b);++i) #define FOL(i,a,b) for(int i(a);i>=(b);--i) #define REW(a,b) memset(a,b,sizeof(a)) #define inf int(0x3f3f3f3f) #define si(a) scanf("%d",&a) #define sl(a) scanf("%lld",&a) #define sd(a) scanf("%lf",&a) #define ss(a) scanf("%s",a) #define mod ll(1e9+7) #define pb push_back #define Pll pair #define P pair #define pi acos(-1) ll a,b,n,s; struct matrix{ ll a[2][2];}; matrix base={0,1,1,1}; matrix mul(matrix x,matrix y) { matrix res; FOR(i,0,1) FOR(j,0,1) { res.a[i][j]=0; FOR(k,0,1) res.a[i][j]=(res.a[i][j]+x.a[i][k]*y.a[k][j]%(mod-1ll))%(mod-1ll); } return res; } matrix gxmod(matrix x,ll b) { matrix res; res.a[0][0]=1,res.a[0][1]=0,res.a[1][0]=0,res.a[1][1]=1; while(b) { if(b&1) res=mul(res,x); x=mul(x,x),b>>=1; } return res; } ll gmod(ll a,ll b) { ll res=1ll; while(b) { if(b&1) res=res*a%mod; a=a*a%mod,b>>=1; } return res; } int main() { cin.tie(0); cout.tie(0); while(scanf("%lld %lld %lld",&a,&b,&n)!=EOF) { if(n==0){cout<
附带一张求斐波那契数列的图