Power – Mod Power Hackerank Solution
So far, we have only heard of Python’s powers. Now, we will witness them!
Powers or exponents in Python can be calculated using the built-in power function. Call the power function a^b as shown below:
It’s also possible to a^b calculate mod m.
This is very helpful in computations where you have to print the resultant % mod.
Note: Here, a and b can be floats or negatives, but, if a third argument is present,b cannot be negative.
Note: Python has a math module that has its own pow(). It takes two arguments and returns a float. It is uncommon to use math.pow().
You are given three integers: , a,b and m. Print two lines.
On the first line, print the result of pow(a,b). On the second line, print the result of pow(a,b,m).
The first line contains , the second line contains b, and the third line contains m.
3 4 5
#Power - Mod Power Hackerank Solution codesagar.in a=int(input()) b=int(input()) m=int(input()) print(pow(a,b)) print(pow(a,b,m)) #Power - Mod Power Hackerank Solution codesagar.in