Official
A - Leyland Number Editorial by en_translator
For beginners
- If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
- Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
- 「C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.
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: