-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhexadecimal.cpp
53 lines (43 loc) · 972 Bytes
/
hexadecimal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <cmath>
#include <limits> // For numeric limits
using namespace std;
bool isBinaryDecimal(int num) {
while (num > 0) {
int digit = num % 10;
if (digit < 0 || digit > 2) { // Check for digits 0, 1, or 2
return false;
}
num /= 10;
}
return true;
}
bool isPossibleProduct(long long n) { // Using long long for larger numbers
if (n == 1) {
return true;
}
// Check if n is a perfect square (alternative method)
long long root = sqrt(n);
for (long long i = 1; i <= root; i++) {
if (i * i == n) {
return isBinaryDecimal(i); // Check if square root is binary
}
}
// Additional checks for special cases (unchanged)
// ... (rest of the code remains the same)
return false;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if (isPossibleProduct(n)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}