Menu Close

Calculating the price of cake on the Yth day…[Cprogm] fcukthecode.com

Fahad’s Birthday is a week ahead. Arav and his friends are planning to give him a birthday party. For that Arav’s friends want him to buy the cake. 

He needs to pay ‘x’ amount of money to buy the Blackforest cake on the first day.  After each day has passed, the Blackforest cake becomes ‘x’ times the price that it was on the previous day. 

For buying the Blackforest cake Arav has to collect money from all the friends and for that,he need ‘y’ days and after ‘y’ days he will go and buy the Blackforest cake.

Arav seeks your help in calculating the price of Blackforest cake on the yth day.
Take the price as modulo 10^9 + 7 as the price can be very large.

Input:
The first line contains an integer T, the number of testcases. It's followed by T lines.
Each Testcase will contain two integers X & Y separated by a space.

Output:
Print the output T lines, each corresponding to the answer of the testcase.

#include <stdio.h>
#define mod 1000000007
int main()
{int t;
scanf("%d",&t);
while(t--){
 long long unsigned int x,y;
 scanf("%llu %llu",&x,&y);
 int a=x;
 int i;
 for(i=0;i<y-1;i++){
 x=(a*x)%mod;
 }
 printf("%llu\n",x);
}
return 0;
}


INPUT_1:
2
14  3
9  6

OUTPUT:
2744
531441


INPUT_2:
4
17  5
11  9
5  2
9  7

OUTPUT:
1419857
357947677
25
4782969


ILLUSTRATION OF THE OUTPUT, WHEN EXECUTING THE CODE

Executed using gcc linux