-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1629.cpp
More file actions
40 lines (37 loc) · 723 Bytes
/
1629.cpp
File metadata and controls
40 lines (37 loc) · 723 Bytes
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
36
37
38
39
40
// Devide and Conquer Algorithm, long long int datatype
#include <stdio.h>
#include <string.h>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <queue>
#include <functional>
#pragma warning(disable:4996)
#define _CRT_SECURE_NO_WARNINGS
using namespace std;
long long int c;
long long int pow(long long int x, long long int y) {
if (y == 0) {
return 1;
}
else if (y == 1) {
return x;
}
if (y % 2 != 0) {
return pow(x, y -1) *x;
}
long long int k = pow(x, y/2);
k %= c;
return (k * k) % c;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long int a,b;
cin >> a>>b>>c;
printf("%d", pow(a, b) % c);
return 0;
}