Problem 348
Perfect Square Check
Easy · 10 pts · Math, Binary Search
Problem
Decide whether N is a perfect square, that is, whether N = X · X for some integer X. N can be as large as 10^18. Floating-point square roots lose precision for numbers this big, so check carefully: compute an integer square root (for example with binary search) and multiply it back. The numbers in this problem can be larger than a 32-bit int can hold (about 2.1 × 10^9), so use a 64-bit integer type: long long in C++, long in Java (Python needs nothing special).
Input
A single integer N.
Output
Print YES if N is a perfect square, otherwise NO.
Constraints
0 <= N <= 10^18
Example input
16
Example output
YES
Explanation
16 = 4 · 4, so 16 is a perfect square and the answer is YES. By contrast 14 lies between 3 · 3 = 9 and 4 · 4 = 16.