Submission #379414

#TimeUsernameProblemLanguageResultExecution timeMemory
379414benedict0724제비 (kriii4_W)C++17
100 / 100
3 ms492 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...