Perfect Square Check Safely
Python
Easy
4 views
Problem Description
Input is a single token. If it is a non-negative integer and perfect square output YES else NO. If input is invalid output NO.
Constraints
Value up to 10^18.
Official Solution
import sys,math
s=sys.stdin.read().strip()
try:
x=int(s)
if x<0:
sys.stdout.write('NO')
else:
r=int(math.isqrt(x))
sys.stdout.write('YES' if r*r==x else 'NO')
except Exception:
sys.stdout.write('NO')
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!