-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1629.js
35 lines (28 loc) · 799 Bytes
/
1629.js
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
35
var readline = require("readline");
var r = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let input = [];
r.on("line", function (line) {
input.push(line);
}).on("close", function () {
main(input);
process.exit();
});
function main(input) {
let [A, B, C] = input[0].split(' ').map(Number)
function power(base, ex){
let temp
if(ex === 0) return 1;
else if(ex % 2 === 1){
temp = power(base , (ex / 2) >> 0);
return (((BigInt(temp) * BigInt(temp)) % BigInt(C)) * BigInt(base) % BigInt(C)) % BigInt(C);
}
else{
temp = power(base, ex / 2)
return ((BigInt(temp) * BigInt(temp)) % BigInt(C))
}
}
console.log(power(A,B).toString())
}