File size: 508 Bytes
bff4ec7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# P1226 — Fast Modular Exponentiation

## Description

Given three integers $a$, $b$, and $p$, compute

$$
a^b \bmod p.
$$

## Input

The only line contains three integers $a$, $b$, and $p$.

## Output

Print one line in the following format:

```text
a^b mod p=s
```

Here `a`, `b`, and `p` are the input values, and $s=a^b\bmod p$.

## Constraints

- $0 \le a,b < 2^{31}$.
- $a+b>0$.
- $2 \le p < 2^{31}$.

## Source

[Luogu P1226, "Fast Modular Exponentiation"](https://www.luogu.com.cn/problem/P1226).