Submission #20116

#TimeUsernameProblemLanguageResultExecution timeMemory
20116suiΩ (kriii4_P3)C++14
0 / 100
0 ms1720 KiB
#define _CRT_SECURE_NO_WARNINGS // scanf(), gets() (needed for Visual C++) //#define NDEBUG #include <cassert> #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <functional> #include <string> #include <vector> #include <queue> #include <set> #include <map> #include <unordered_map> #include <stack> #include <deque> using namespace std; #define MEMSET(x, WITH) memset(x, (WITH), sizeof(x)) #define FOR(i, E) for(int i=0; i<(E); i++) #define REP(i, LO, HI) for(int i=(LO); i<=(HI); i++) #define GETINT(x) scanf("%d", &x) #define GETDBL(x) scanf("%lf", &x) #define GETSTR(x) scanf("%s", x) #define NEWINT(x) int x; scanf("%d", &x) #define NEWDBL(x) double x; scanf("%lf", &x) #define NEWLN putchar('\n') #ifdef _WIN32 #define popcnt __popcnt #else #define popcnt __builtin_popcount #endif typedef long long ll; //const ll MOD = 1000000007; //const double PI = atan(1) * 4; const ll MOD = 1000000007; ll powerMod(ll a, ll n) { ll ans = 1; for (int i=62; i>=0; i--) { ans = ans * ans % MOD; if ((n>>i)&1) ans = ans * a % MOD; } return ans; } ll inv(ll a) { return powerMod(a, MOD-2); } // The probability to go down: Q/P // The probability to go up: 1 - Q/P ll P, Q, N, K; // 0 <= Q <= P int main() { cin >> P >> Q >> N >> K; if (Q == P) { puts("0"); return 0; } if (Q == 0) { puts("1"); return 0; } ll r = Q * inv(P-Q) % MOD; if (r == 1) { cout << K * inv(N) % MOD << endl; return 0; } ll a = (r-1+MOD) * inv(powerMod(r, N)-1+MOD) % MOD; ll ans = a * ((powerMod(r, K)-1+MOD)%MOD) % MOD * inv(r-1+MOD) % MOD; cout << ans << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...