Official
A - 106 Editorial by evima
We have \(3^{38} > 10^{18}\) and \(5^{26} > 10^{18}\), so if a solution exists, \(1\leq A \leq 37\) and \(1\leq B\leq 25\) must hold.
Thus, we can solve the problem by computing \(3^x + 5^y\) for all pairs \((x, y)\) such that \(1\leq x\leq 37\) and \(1\leq y\leq 25\) and printing the following:
- If there is a pair such that the computed value is \(N\), print it;
- If there is no such pair, print \(-1\).
When implementing it, watch out for overflows and so on.
Sample Implementation in Python: https://atcoder.jp/contests/arc106/submissions/17609303
posted:
last update: