
simplePowers
Given two numbers a
and b
, perform the following operations:
- let
M = 109 + 7
; - compute
x = (ab + ba) % M
(here%
is the modulo operation); - let
y
be the binary representation ofx
; - assuming that
y
is written in base3
, transform it to base10
and return it moduloM
.
Example
- For
a=3
andb = 2
, the output should beSimple_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
orb
is not equal to0
.Constraints:
0 ≤ b < 109
. -
[output] integer
Post Comment