티스토리 뷰

백준

백준 소스코드 [C++] 1629 곱셈

Hani_Levenshtein 2020. 11. 22. 05:07

www.acmicpc.net/problem/1629

 

1629번: 곱셈

첫째 줄에 A, B, C가 빈 칸을 사이에 두고 순서대로 주어진다. A, B, C는 모두 2,147,483,647 이하의 자연수이다.

www.acmicpc.net

백준 소스코드 [C++] 1629 곱셈

#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
typedef long long ll;
#define all(v) v.begin(), v.end()
#define vii vector<pair<int,int> > 
using namespace std;
ll power(ll a, ll b, ll c) {
	if (b == 0) return 1;
	else if (b % 2 == 1) return a * power(a, b - 1, c) % c;
	else {
		ll w = power(a, b / 2, c) % c;
		return w * w%c;
	}

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a, b, c;
	cin >> a >> b >> c;
	cout << power(a, b, c);
	return 0;
}
댓글