Given a number and its reverse. Find that number raised to the power of its own reverse.
Note: As answers can be very large, print the result modulo 109 + 7.
2
4
class Solution {
public:
long long MOD = 1e9+7;
long long power(long long N, long long R)
{
N %= MOD;
long long ans = 1;
while (R > 0) {
if (R & 1) {
ans = (ans * N) % MOD;
}
N = (N * N) % MOD;
R >>= 1;
}
return ans;
}
};