Back
Close

Power of Loops

Statement

 Goal

You are given 3 integers x, y, and z. Return x raised to the power of y modulo z. If the operation is invalid, return "undefined".

For example:
Given 10, 2, 99. Return 1. Since (10 ^ 2) mod 99 = 100 % 99 = 1.

Hint:
Notice how (a * a) % b = ((a % b) * (a % b)) % b.
Input
Line 1: An integer x
Line 1: An integer y
Line 1: An integer z
Output
Line 1 : An integer that is modulo z of x ^ y.
Constraints
0 ≤ x,y,z ≤ 2e31
Example
Input
10
2
99
Output
1

Game modes
Shortest

Test cases
Small Test
Input
10 2 99
Output
1

Validator 1 Validator
Input
20 2 98
Output
8

Medium Test
Input
123 456 789
Output
699

Validator 2 Validator
Input
321 654 987
Output
645

Large Test
Input
111111 222222 333332
Output
30625

Validator 3 Validator
Input
666666 777777 888889
Output
192961

Super Large Test
Input
1987654321 1123456789 88888888
Output
65130937

Validator 4 Validator
Input
1918273645 1564738291 7777777
Output
3279179

Zero Test
Input
1000 1234 10000
Output
0

Validator 5 Validator
Input
1234 5678 1522756
Output
0

Perfectly Balanced Test
Input
0 1337 8008135
Output
0

Validator 6 Validator
Input
0 9001 21
Output
0

As All Things Test
Input
9876 0 21
Output
1

Validator 7 Validator
Input
420 0 19
Output
1

Should Be Test
Input
2 1 0
Output
undefined

Validator 8 Validator
Input
111111 111111 0
Output
undefined

Solution language

Solution

Stub generator input