Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool checkPerfSq(int x) {
- int st = 1, dr = x;
- while (st <= dr) {
- int mid = (st + dr) / 2;
- if (mid * mid == x) {
- return true;
- }
- if (mid * mid < x) {
- st = mid + 1;
- } else {
- dr = mid - 1;
- }
- }
- return false;
- }
- int main() {
- int x;
- cin >> x;
- cout << checkPerfSq(x) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement