Loading Now

simplePowers

Given two numbers a and b, perform the following operations:

  1. let M = 109 + 7;
  2. compute x = (ab + ba) % M (here % is the modulo operation);
  3. let y be the binary representation of x;
  4. assuming that y is written in base 3, transform it to base 10 and return it modulo M.

Example

  • For a=3 and b = 2, the output should be Simple_powers(a, b) = 82.

    Here is how the answer is obtained:
  • x = 32 + 23 = 9 + 8 = 17.
  • y = 1710 = 100012.
  • res = 100013 = 8210.

Input/Output

  • [execution time limit] 0.5 seconds

  • [input] integer a

    Constraints:
    0 ≤ a < 109.

  • [input] integer b

    It is guaranteed that either a or bis not equal to 0.

    Constraints:
    0 ≤ b < 109.

  • [output] integer

Post Comment

Contact