Submission #9515

#TimeUsernameProblemLanguageResultExecution timeMemory
9515myungwooPhibonacci (kriii2_P)C++14
1 / 4
0 ms1676 KiB
#include <iostream> using namespace std; typedef long long lld; const int MOD = 1e9 + 7; lld N, K; struct MAT{ int m[2][2]; MAT operator * (const MAT &ot)const{ MAT ret={0, }; int i, j, k; for (i=0;i<2;i++) for (j=0;j<2;j++) for (k=0;k<2;k++) ret.m[i][j] = (ret.m[i][j]+(lld)m[i][k]*ot.m[k][j]%MOD)%MOD; return ret; } } P[40]; struct TERM{ TERM(lld p, lld q){ a = p%MOD, b = q%MOD; } int a, b; TERM operator * (const TERM &ot)const{ return TERM((((lld)a*ot.a%MOD+(lld)a*ot.b%MOD)%MOD+(lld)b*ot.a%MOD)%MOD, ((lld)a*ot.a%MOD+(lld)b*ot.b%MOD)%MOD); } }; int fibo(lld n) { MAT t ={1, 0, 0, 1}; if (n < 0) return 1; for (int i=0;i<40;i++,n>>=1) if (n&1) t = t*P[i]; return t.m[0][1]; } TERM _pow(TERM a, lld b) { TERM v = a, ret(0, 1); for (;b;b>>=1, v=v*v) if (b&1) ret = ret*v; return ret; } int _pow(int a, lld b) { int v = a, ret = 1; for (;b;b>>=1,v=(lld)v*v%MOD) if (b&1) ret = (lld)ret*v%MOD; return ret; } int main() { int i; MAT t ={1, 1, 1, 0}; P[0] = t; for (i=1;i<40;i++) P[i] = P[i-1]*P[i-1]; cin >> N >> K; TERM p(fibo(N), fibo(N-1)); TERM q = _pow(p, K); int x = (lld)q.a*_pow(fibo(K), MOD-2)%MOD; int y = (q.b-(lld)x*fibo(K-1)%MOD+MOD)%MOD; cout << x << " " << y << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...