Find Modulo of Exponent

Calculate the value of n^(2^k) % m. This question must be solved using constant memory.

Parameters

  • n: An integer representing the base of the exponent
  • k: An integer representing the exponent of the exponent of 2.
  • m: An integer representing the base of the modulo

Result

  • The result of the expression.

Examples

Example 1

Input: n = 2, k = 3, m = 10

Output: 6

Explanation: 2^(2^3) % 10 == 2^8 % 10 == 256 % 10 == 6.

Example 2

Input: n = 2, k = 34, m = 21

Output: 16

Constraints

  • 1 <= n, m <= 30000
  • 1 <= k <= 2^31 - 1

Try it yourself

Solution

Title

Script

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

  >>> a = [1, 2, 3]
  >>> a[-1]
  3

Get premium for instant access to all content and solutions

Upgrade