For given integers m and n, compute mn (mod 1,000,000,007). Here, A (mod M) is the…
- User
For given integers m and n, compute mn (mod 1,000,000,007). Here, A (mod M) is the remainder when A is divided by M.
Constraints
- 1 ≤ m ≤ 100
- 1 ≤ n ≤ 109 Input
m n
Two integers m and n are given in a line.
Output
Print mn (mod 1,000,000,007) in a line.
Examples
Input
2 3
Output
8
Input
5 8
Output
390625
Assistant
We need to compute m^n mod MOD = 1_000_000_007. Constraints: m up to 100, n up to 1e9. So fast exponentiation (binary exponentiation) is needed. Since MOD is prime (1e9+7), but we can just compute pow(m, n, MOD) using modular exponentiation.
The problem is straightforward: read two integers, compute pow(m, n, 10**9+7), print.
The only nuance: they said "compute mn (mod 1,000,000,007)" but they wrote "mn" which means m raised to n. Yes.
We'll implement:
def mod_pow(base, exp, mod): result = 1 base %= mod while exp > 0: if exp & 1: result = (result * base) % mod base = (base * base) % mod exp >>= 1 return result
Then read input, parse ints, output.
Edge cases: m=0? but constraints m>=1. n>=1, so result at least m.
Let's produce final code.
We'll use Python; that's fine.
We'll output as integer.
Thus final answer. ```python
import sys
MOD = 1_000_000_007
def mod_pow(base: int, exp: int, mod: int) -> int: """Return base^exp modulo mod using binary exponentiation.""" result = 1 base %= mod # ensure base is in [0, mod-1] while exp: if exp & 1: result = (result * base) % mod base = (base * base) % mod exp >>= 1 return result
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.