Problem: Power of Numbers

Given a number N, let the reverse of the number be R. The task is to print the output of the Expression pow(N,R), where pow function represents N raised to power R.

Input:
The first line of the input consists of an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of a single line containing an integer N .

Output:
Corresponding to each test case, print in a new line, the output of the expression pow as described above.
Note: As answers can be very large, print the result modulo 100000007.

Constraints:
1<=T<=1000
1<=N<=78643

Example:
Input:
2
2
12
Output:
4
33235307

Use pow(x,y,mod) in python , it returns x**y % mod, and so much faster than pow(x,y)%mod.

def pow_(n, r):
    mod = 100000007
    n = pow(n,r,mod)
    return n

if __name__ == '__main__':
    t = input()
    for _ in range(t):
        n = input()
        l = list(str(n))
        l.reverse()
        r = int(''.join(l))
        print pow_(n, r)

 

Advertisements