Submission #19602

#TimeUsernameProblemLanguageResultExecution timeMemory
19602exqtΩ (kriii4_P3)C++98
100 / 100
0 ms1720 KiB
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <utility> #include <queue> #include <string> #include <cstring> #include <map> using namespace std; #define in cin #define out cout #define ll long long int ll DV = 1000000007; ll pow(ll a, ll b) { ll t = a; ll res = 1; while(b) { if(b%2) res = (res * t) % DV; t = t % DV; t = (t*t) % DV; b = b >> 1; } return res; } ll inv(ll a) { return pow(a, DV-2)%DV; } ll mul(ll a, ll b) { return (a%DV)*(b%DV)%DV; } struct mat22 { ll a1, a2, a3, a4; mat22 operator*(const mat22 &T) { return {mul(a1, T.a1)+mul(a2, T.a3), mul(a1, T.a2)+mul(a2, T.a4), mul(a3, T.a1)+mul(a4, T.a3), mul(a3, T.a2)+mul(a4, T.a4)}; } void print() { out << a1 << " " << a2 << " " << a3 << " " << a4 << endl; } }; int main() { ll A, B; in >> A >> B; B = A-B; ll p = B*inv(A); ll q = (A-B)*inv(A); mat22 T = {inv(p), mul(-q, inv(p)) + DV, 1, 0}; ll N, K; in >> N >> K; ll a1, a2, a0 = 0; mat22 MT = {1,0,0,1}; for(int i=2; i<=N; i++) { MT = MT * T; } a1 = inv(MT.a1); if(K == 0) out << 0; else if(K == N) out << 1; else { for(int i=1; i<K; i++) { a2 = mul( T.a1, a1 ) + mul( T.a2, a0 ); a2 %= DV; a0 = a1 % DV; a1 = a2 % DV; } out << a1; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...