# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
9812 |
2014-09-28T09:49:42 Z |
veckal |
Phibonacci (kriii2_P) |
C++14 |
|
0 ms |
1088 KB |
#include<stdio.h>
typedef long long ll;
const int MOD = 1000000000 + 7;
ll n, k;
struct Matrix {
ll mat[2][2];
Matrix() {
mat[0][0]=mat[0][1]=mat[1][0]=mat[1][1]=0;
}
};
Matrix operator *(Matrix& A, Matrix& B) {
Matrix ret;
for (int i=0; i<2; ++i)
for (int j=0; j<2; ++j)
for (int k=0; k<2; ++k)
ret.mat[i][j] = (ret.mat[i][j] + A.mat[i][k] * B.mat[k][j])%MOD;
return ret;
}
Matrix power(ll exp) {
Matrix ret, base;
base.mat[0][0] = base.mat[0][1] = base.mat[1][0] = 1;
ret.mat[0][0] = ret.mat[1][1] = 1;
while(exp) {
if (exp&1) ret = ret * base;
base = base * base;
exp >>= 1;
}
return ret;
}
int main() {
scanf("%lld%lld", &n, &k);
if (n == 1) {
puts("1 0");
} else if (n == 0) {
puts("0 1");
} else if (k == 1) {
Matrix fib = power(n);
printf("%lld %lld\n", fib.mat[0][1], fib.mat[1][1]);
} else if (k == 2) {
Matrix fib = power(n+n-1);
ll ans2 = (MOD - fib.mat[1][1])%MOD;
Matrix base;
base.mat[0][0] = base.mat[0][1] = base.mat[1][0] = 1;
fib = fib * base;
ll ans1 = fib.mat[0][1];
printf("%lld %lld\n", ans1, ans2);
} else
puts("-1");
return 0;
}
# |
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 |
- |