[BOJ] 1629번 곱셈

yeham·2022년 11월 7일
0

백준

목록 보기
6/22

문제

곱셈

코드

#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

unsigned long long ft_pow(unsigned long long i, unsigned long long j, unsigned long long k)
{
    unsigned long long num;
	if (j == 1)
		return (i % k);
	num = ft_pow(i, j/2, k);
	num = num * num % k;
	if (j % 2 == 1)
		return (num * i % k);
	else
		return (num);
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
    unsigned long long i, j, k;
	cin >> i >> j >> k;
	cout << ft_pow(i, j, k);
    return (0);
}
profile
정통과 / 정처기 & 정통기 / 42seoul 7기 Cardet / 임베디드 SW 개발자

0개의 댓글