#include #include #include #include #include #include using namespace std; #define int long long #define rep(i,n) for(int i = 0; i < (n); i++) #define endl "\n" const long long INF = (long long)1e18; // const long long MOD = (long long)1e9 + 7; // long long MOD; string yn(bool f){return f?"Yes":"No";} string YN(bool f){return f?"YES":"NO";} #define MAX int solve(int n, int MOD){ if(n <= 1) return n; vector> ans(2,vector(1)), temp(2,vector(1)), matrix1(2,vector(2)), matrix2(2,vector(2)), matrix3(2,vector(2)); ans[0][0] = 1; ans[1][0] = 0; matrix1[0][0] = 1; matrix1[0][1] = 1; matrix1[1][0] = 1; matrix1[1][1] = 0; n--; while(n){ if(n&1){ temp.clear(); temp.resize(2,vector(1,0)); for(int i = 0; i < matrix1.size(); i++){ for(int j = 0; j < ans[0].size(); j++){ for(int k = 0; k < ans.size(); k++){ temp[i][j] += matrix1[i][k]*ans[k][j]; temp[i][j] %= MOD; } } } ans = temp; } matrix3.clear(); matrix3.resize(2,vector(2,0)); matrix2 = matrix1; for(int i = 0; i < matrix1.size(); i++){ for(int j = 0; j < matrix1.size(); j++){ for(int k = 0; k < matrix1.size(); k++){ matrix3[i][j] += matrix1[i][k]*matrix2[k][j]; matrix3[i][j] %= MOD; } } } matrix1 = matrix3; n >>= 1; // cout<<"matrix "<>n>>m; cout<