Official

A - Power Editorial by en_translator


Initialize the answer with \(1\) and use a for statement to multiple \(A\) to the answer \(B\) times.

Some languages come with an operator or a function that directly yields \(A^B\), so you may use them.

Sample code

C++

#include <iostream>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int ans = 1;
	for (int i = 0; i < b; i++) ans *= a;
	cout << ans << '\n';
}

Python

a, b = map(int, input().split());
print(a ** b);
a, b = map(int, input().split());
print(pow(a, b));

Notes

The std::pow function in C++ is a function that supports floating point number types like float and double. Although you will be accepted with this function under the constraints of this problem, note that you may encounter an error for larger inputs as follows.

Example (While \(3^{38} = 1350851717672992089\), this prints \(1350851717672992000\)).

#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
	ll ans = pow(3, 38);
	cout << ans << '\n';
}

posted:
last update: