Official
A - Sum and Product Editorial by evima
We have \(\min(N,M) \leq \sqrt{P}\). We just need to use brute force to check if there is an integer \(x\) such that \(x(S-x)=P\) in the range \(1 \leq x \leq \sqrt{P}\). It works in \(O( \sqrt{P})\) time and is fast enough.
Sample Implementation (Python)
S,P = map(int, input().split())
for i in range(1000050):
if i*(S-i) == P:
print("Yes")
exit(0)
print("No")
posted:
last update: