Power of a Number in Python


Python.math module provides access to the mathematical functions defined by the C standard.
One of the widely used function is math.pow(x, y) which Returns x raised to the power y.
Now, you are given three integers x, y and M. You have to print ( x ^ y ) Mod M.
Input format
First line will contain three integers x, y, and M.
Constraints
1 <= X <= 20
1 <= Y <= 100
2 <= M <= 100

Output Format
Print an Integer denoting answer of the calculation (x ^ y ) Mod M.

Sample TestCase 1
Input
10 2 3

output
1

Explanation
10^2 = 100
100%3=1


Solution:

import sys
import math
def main():

# Write code here
ip=raw_input()
ip=map(int,ip.split(' '))
x=int(ip[0])
y=int(ip[1])
m=int(ip[2])
o1=math.pow(x,y)
o2=o1%m
sys.stdout.write(str(int(o2)))


main()

Comments

Post a Comment

Popular posts from this blog

Reasoning-Letter Series

Reasoning-Number Series

Multiply Negative numbers in java