1787A - Exponential Equation - 800
On This Page
The equation is a mix of multiplication and exponential operations. Given the nature of exponential operations, $𝑥^𝑦$ and $𝑦^𝑥$ can grow very large very quickly as
We can try to simplify the equation.
If we can somehow set one of the variables
y to 1, the equation simplifies.
This is because any number (except zero) raised to the power of 1 is the number itself, and any number raised to the power of 0 is 1.
So, if we set
x = 1, the equation simplifies to
1^y * y + y^1 * 1 = n, which further simplifies to
y + y = n, or
2y = n. This is a simple linear equation, and we can see that for any even
n greater than 2, it has a solution in integers. The solution is
x = 1 and
y = n/2.
n = 2, we can set both
1, and the equation holds. It can be a base case.
- For odd
ngreater than 2, and for
n = 1, there’s no solution in integers.
def solve(): n = int(input()) if n == 2: print(1, 1) elif n % 2 == 0: print(1, n//2) else: print(-1) for _ in range(int(input())): solve()