HROC101-Editorial

In this problem, the well known Fermat’s Little Theorem is used to calculate the large power of numbers.

<h3>typedef long long ll;
const ll MODULUS=1000000007;
ll p(ll b, ll e, ll m)
{
    ll c=1;
    while(e) 
    {
        if(e&1LL)
            c=(c*b)%m;
        e/=2LL;
        b=(b*b)%m;
    }
    return c;
}
int main()
{
   ll T, a, b, c, d;
    scanf("%lld", &T);
    while(T--)
    {
        scanf(" %lld %lld %lld %lld", &a, &b, &c, &d);
        ll ans1=p(a, b, MODULUS);
        ll ans2=p(c, d, MODULUS-1LL);
        ll ans=p(ans1, ans2, MODULUS);
        printf("%lld\n", ans);
    }
    return 0;
 }

</pre>
//