# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
9638 |
2014-09-28T07:47:00 Z |
dolpang2 |
Phibonacci (kriii2_P) |
C++14 |
|
0 ms |
1088 KB |
#include <cstdio>
const int MODULO = 1000000007;
struct Matrix {
long long M[2][2];
};
Matrix matrix;
Matrix multiplyOfMatrix(Matrix x, Matrix y) {
Matrix ret;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
int sum = 0;
for (int k = 0; k < 2; ++k) {
sum += ((x.M[i][k] % MODULO) * (y.M[k][j] % MODULO)) % MODULO;
}
sum = sum % MODULO;
ret.M[i][j] = sum;
}
}
return ret;
}
Matrix powerOfMatrix(Matrix matrix, long long valueOfPower) {
if (valueOfPower == 1) {
return matrix;
} else if (valueOfPower % 2 == 0) {
return powerOfMatrix(multiplyOfMatrix(matrix, matrix), valueOfPower * 0.5);
} else {
return multiplyOfMatrix(matrix, powerOfMatrix(multiplyOfMatrix(matrix, matrix), (valueOfPower - 1) * 0.5));
}
}
int main() {
long long n = 0;
int k = 0;
scanf("%lld%d", &n, &k);
Matrix matrix;
matrix.M[0][0] = 1;
matrix.M[0][1] = 1;
matrix.M[1][0] = 1;
matrix.M[1][1] = 0;
Matrix result = powerOfMatrix(matrix, n);
printf("%lld %lld\n", result.M[0][1], result.M[1][1]);
// printf("%lld %lld\n", result.M[1][0], result.M[1][1]);
}
# |
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 |
- |