Hackerrank - Power - Mod Power Solution
1 min read

Hackerrank - Power - Mod Power Solution

Hackerrank - Power - Mod Power
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  as shown below:

>>> pow(a,b) 

or

>>> a**b

It's also possible to calculate .

>>> pow(a,b,m)  

This is very helpful in computations where you have to print the resultant % mod.

Note: Here,  and  can be floats or negatives, but, if a third argument is present,  cannot be negative.

Note: Python has a math module that has its own pow(). It takes two arguments and returns a float. Frankly speaking, we will never use math.pow().

Task
You are given three integers: , , and , respectively. Print two lines.
The first line should print the result of pow(a,b). The second line should print the result of pow(a,b,m).

Input Format
The first line contains , the second line contains , and the third line contains .

Constraints


Sample Input

3
4
5

Sample Output

81
1

Solution in Python

a,b,c = (int(input()) for i in range(3))
print(pow(a,b), pow(a,b,c), sep="\n")

Enjoying these posts? Subscribe for more


Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

That's okay. But without advertising-income, we can't keep making this site awesome.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add thepoorcoder.com to your ad blocking whitelist or disable your adblocking software.

×