-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD28.cpp
49 lines (43 loc) · 1.05 KB
/
D28.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
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
bool isBinaryDecimal(int n) {
while (n > 0) {
int digit = n % 10;
if (digit != 0 && digit != 1)
return false;
n /= 10;
}
return true;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
// Check if n is already a binary decimal
if (isBinaryDecimal(n)) {
cout << "YES" << endl;
continue;
}
// Check if n can be represented as a product of binary decimals
bool possible = false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
int factor = n / i;
if (isBinaryDecimal(i) && isBinaryDecimal(factor)) {
possible = true;
break;
}
}
}
// Output the result
if (possible)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}