-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolorful_numbers.cpp
More file actions
51 lines (47 loc) · 970 Bytes
/
colorful_numbers.cpp
File metadata and controls
51 lines (47 loc) · 970 Bytes
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
#include <bits/stdc++.h>
using namespace std;
#define loop(i, start, end) for(int i=start; i<end; i++)
int colorful(int A){
if(A==0){
return 1;
}
unordered_set<int> my_set;
unordered_set<int>::iterator itr;
vector<int> vect;
while(A!=0){
vect.push_back(A%10);
A = A/10;
}
int prod;
for(int i=0; i<vect.size(); i++){
prod = 1;
for(int j=i; j<vect.size(); j++){
if(i==j){
prod = vect[i];
// cout<<prod<<endl;
}
else{
prod = prod*vect[j];
// cout<<prod<<endl;
}
itr = my_set.find(prod);
if(itr != my_set.end()){
return 0;
}
my_set.insert(prod);
}
}
return 1;
}
int main()
{
int test;
cin>>test;
cin.ignore(1);
while(test--){
int n;
cin>>n;
cout<<colorful(n)<<endl;
}
return 0;
}