Official

A - Leyland Number Editorial by en_translator


For beginners


Evaluate \(A^B\) and \(B^A\), and find their sum.
The value of \(A^B\) can be computed by multiplying \(1\) by \(A\) \(B\) times; same applies to \(B^A\).

Sample code

#include <iostream>
using namespace std;

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

posted:
last update: