Submission #9606

#TimeUsernameProblemLanguageResultExecution timeMemory
9606shashackPhibonacci (kriii2_P)C++98
1 / 4
0 ms1680 KiB
#include <iostream> #include <iomanip> #include <stdlib.h> #include <stdio.h> #include <algorithm> #include <assert.h> #include <bitset> #include <cstring> #include <cstdlib> #include <ctime> #include <map> #include <math.h> #include <malloc.h> #include <numeric> #include <string> #include <stack> #include <queue> #include <vector> #pragma warning(disable:4996) #define REP(variable, repeatnumber) for(int variable=0; variable<(repeatnumber); ++variable) #define FOR(variable, start, end) for(int variable=(start); variable<=(end); ++variable) #define RFOR(variable, start, end) for(int variable=(start); variable>=(end); --variable) #define ULL unsigned long long #define LL long long using namespace std; // 700B typedef vector<LL> vec; typedef vector<vec> mat; int x,y,z; const LL M = 1000000007; LL n; mat mul(mat &A, mat &B){ mat C(A.size(), vec(B[0].size())); x = A.size(); for (int i = 0; i < x; i++){ y = B.size(); for (int k = 0; k < y; k++){ z = B[0].size(); for (int j = 0; j < z; j++){ C[i][j] = ((C[i][j] + A[i][k] * B[k][j])+ M) % M; } } } return C; } mat pow(mat A, LL n){ mat B(A.size(), vec(A.size())); x = A.size(); for (int i = 0; i < x; i++){ B[i][i] = 1; } while (n>0){ if (n & 1) B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } int main(){ mat A(2, vec(2)); A[0][0] = 1; A[0][1] = 1; A[1][0] = 1; A[1][1] = 0; cin >> n; A = pow(A, n) ; cout << A[1][0] << " "; A[0][0] = 1; A[0][1] = 1; A[1][0] = 1; A[1][1] = 0; A = pow(A, n - 1) ; cout << A[1][0] << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...