Submission #9638

#TimeUsernameProblemLanguageResultExecution timeMemory
9638dolpang2Phibonacci (kriii2_P)C++14
1 / 4
0 ms1088 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...