Posts 1629 곱셈
Post
Cancel

1629 곱셈

1629 곱셈

코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>

using namespace std;

long long A, B, C;
long long result = 1;


int main() {
	cin >> A >> B >> C;

	while (B != 0) {
		if (B % 2 == 1) {
			result = (result * A) % C;
		}
		A = (A * A) % C;
		B /= 2;
	}
	cout <<  result % C;
}
This post is licensed under CC BY 4.0 by the author.

16236 Samsung sw test

17140 Samsung sw test

Comments powered by Disqus.