.

Ameesha Loves Candy codechef solution

Ameesha Loves Candy codechef solution

Ameesha owns a magic box of candies. It is magical because at the end of each month, the number of candies in the box doubles. If there were x candies in the box at the start of a month, then the number of candies at the end of the month would become 2x.

However, immediately after doubling the candies, the magic box eats one of the candies (if available) with a probability of 0.5. This incident happens in every month, except the last month of the year.

Ameesha owns x candies right now. Help her find the expected number of candies she will have in one year. You are given that a year lasts for k+1 months. Find and print the answer modulo 109109 + 7.

Input: Ameesha Loves Candy codechef solution

The only line of input contains two integers x and k.

  • x = initial number of candies in box
  • k + 1 = number of months in a year

Output:

Print a single integer, i.e., the expected number of candies Ameesha will own one year later modulo 109109 + 7.

Constraints

  • 0x,k1010≤x,k≤10188

Sample Input: Ameesha Loves Candy codechef solution

2 1

Sample Output:

7

EXPLANATION:

  • After the first month there will be 50% probability of 3 candies and 50% probability of 4 candies.
  • At the end of the year there will be 6 candies with 50% probability and 8 candies with 50% probability. Hence, the answer for this test case will be (6 + 8) / 2 = 7.

Note Ameesha Loves Candy codechef solution

  • No candies are eaten by box at end of last month of year.
error: Content is Protected !!!