아주 쉬운문제로 딱히 알고리즘이 필요하지 않았다.

N <= 10^6이므로 O(N)으로 풀어도 통과할꺼라 예상하였다.따라서 반복문을 이용해 알고리즘 없이 풀었다.

#include<iostream>

using namespace std;

#define DIV 1000000007

int main(int argc, char** argv)
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int K, P, N; cin >> K >> P >> N;

	long long ans = K;

	for (int i = 0; i < N; i++) {
		ans *= P;
		ans %= DIV;
	}

	cout << ans << '\n';

	return 0;
}

+ Recent posts