# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
9450 |
2014-09-28T06:32:48 Z |
myungwoo |
Phibonacci (kriii2_P) |
C++14 |
|
0 ms |
1088 KB |
#include <stdio.h>
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, ((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++) if ((n>>i)&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=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];
scanf("%lld%lld", &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;
printf("%d %d\n", x, y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1088 KB |
Output is correct |
2 |
Correct |
0 ms |
1088 KB |
Output is correct |
3 |
Correct |
0 ms |
1088 KB |
Output is correct |
4 |
Correct |
0 ms |
1088 KB |
Output is correct |
5 |
Correct |
0 ms |
1088 KB |
Output is correct |
6 |
Correct |
0 ms |
1088 KB |
Output is correct |
7 |
Correct |
0 ms |
1088 KB |
Output is correct |
8 |
Correct |
0 ms |
1088 KB |
Output is correct |
9 |
Correct |
0 ms |
1088 KB |
Output is correct |
10 |
Correct |
0 ms |
1088 KB |
Output is correct |
11 |
Correct |
0 ms |
1088 KB |
Output is correct |
12 |
Correct |
0 ms |
1088 KB |
Output is correct |
13 |
Correct |
0 ms |
1088 KB |
Output is correct |
14 |
Correct |
0 ms |
1088 KB |
Output is correct |
15 |
Correct |
0 ms |
1088 KB |
Output is correct |
16 |
Correct |
0 ms |
1088 KB |
Output is correct |
17 |
Correct |
0 ms |
1088 KB |
Output is correct |
18 |
Correct |
0 ms |
1088 KB |
Output is correct |
19 |
Correct |
0 ms |
1088 KB |
Output is correct |
20 |
Correct |
0 ms |
1088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |