This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
ll pow(ll x, ll y){
int k = 0; ll temp = x, ans = 1;
while((1LL << k) <= y)
{
if((1LL << k) & y){
ans *= temp;
ans %= mod;
}
temp *= temp;
temp %= mod;
k++;
}
return ans;
}
ll inv(ll x) { return pow(x, mod - 2); }
void solve()
{
ll R, G, B, K; cin >> R >> G >> B >> K;
ll ans = (B+G)*K; ans %= mod;
ans *= inv(B); ans %= mod;
ll ans2 = R * inv(pow(1+B, K)); ans2 %= mod;
ll ans3 = pow(1+B, K) - pow(B, K); ans3 %= mod;
ans2 *= ans3; ans2 %= mod;
ans += ans2; ans %= mod;
if(ans < 0) ans += mod;
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(false); cin.tie(NULL);
int t; cin >> t;
while(t--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |