Submission #19433

#TimeUsernameProblemLanguageResultExecution timeMemory
19433emppuΩ (kriii4_P3)C++14
0 / 100
0 ms1724 KiB
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <cstring> #include <cassert> #include <algorithm> #include <vector> #include <string> #include <set> #include <map> #include <queue> #include <deque> #include <list> #include <bitset> #include <tuple> using namespace std; #define f0(_X,_Y) for(int (_X)=0;(_X)<(_Y);++(_X)) #define f1(_X,_Y) for(int (_X)=1;(_X)<=(_Y);++(_X)) #define ff(_X,_Y,_Z) for(int (_X)=(_Y);(_X)<=(_Z);++(_X)) #define fF(_X,_Y,_Z) for(int (_X)=(_Y);(_X)<(_Z);++(_X)) #define rf0(_X,_Y) for(int _X=(_Y)-1;(_X)>=0;--(_X)) #define rf1(_X,_Y) for(int _X=(_Y);(_X)>0;--(_X)) #define rff(_X,_Y,_Z) for(int _X=(_Y);(_X)>=(_Z);--(_X)) #define rfF(_X,_Y,_Z) for(int _X=(_Y);(_X)>(_Z);--(_X)) #define PRT(_X) std::cout<< #_X ": "<<_X<<std::endl; #define scan1(_X) scanf("%d",&_X); #define scan2(_X,_Y) scanf("%d%d",&_X,&_Y); #define scan3(_X,_Y,_Z) scanf("%d%d%d",&_X,&_Y,&_Z); #define define1(_1) int _1; scan1(_1) #define define2(_1,_2) int _1,_2; scan2(_1,_2) #define define3(_1,_2,_3) int _1,_2,_3; scan3(_1,_2,_3) #define EXPAND(_1) _1 #define SELECT(_1,_2,_3,_4,NAME,...) NAME #define scan(...) EXPAND(SELECT(__VA_ARGS__, scan4, scan3, scan2, scan1)(__VA_ARGS__)) #define define(...) EXPAND(SELECT(__VA_ARGS__, define4, define3, define2, define1)(__VA_ARGS__)) #define print(_X) printf("%d\n",_X) #define PAIR_STRUCT(_T,_X,_Y,...) struct _T{int _X,_Y,##__VA_ARGS__; bool friend operator < (const _T &p, const _T &q){if(p._X!=q._X) return p._X<q._X; return p._Y<q._Y;}} typedef long long ll; const int MOD = 1000000007; ll a[103]; ll d[103]; ll inv(ll a, ll b=MOD) { ll s = 0; ll old_s = 1; ll r = b; ll old_r = a; while (r!=0) { ll quotient = old_r / r; tie(old_r, r) = make_tuple(r, old_r - quotient * r); tie(old_s, s) = make_tuple(s, old_s - quotient * s); } ll inv = old_s%MOD; if(inv<0) inv += MOD; return inv; } int main() { ll p,q,n,k; scanf("%lld%lld%lld%lld",&p,&q,&n,&k); ll Pl = q*inv(p)%MOD; ll Pr = (p-q)*inv(p)%MOD; if(n==1) { if(k==0) print(0); else print(1); } else if(n==2) { printf("%lld\n",Pr); } else { a[1] = 1; a[2] = inv(Pr); ff(i,2,n-2) // d_i = a[i] d_1 { // d[i] = Pl d[i-1] + Pr d[i+1] // d[i+1] = (a[i] - Pl a[i-1] )/Pr d_1 a[i+1] = (a[i]-Pl*a[i-1]%MOD)*inv(Pr)%MOD; if(a[i+1]<0) a[i+1] += MOD; } // d[n-1] = a[n-1] d_1 // d[n-1] = Pl a[n-2] d_1 + Pr // d_1 = Pr / (a[n-1]-Pl a[n-2]) d[1] = Pr * inv(a[n-1]-Pl*a[n-2]%MOD) % MOD; if(d[1]<MOD) d[1] += MOD; printf("%lld\n",d[1]*a[k]%MOD); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...