-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbad_ugly_numbers.cpp
More file actions
135 lines (98 loc) · 1.87 KB
/
bad_ugly_numbers.cpp
File metadata and controls
135 lines (98 loc) · 1.87 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
For each test case, print an integer 𝑠 which satisfies the conditions described:
1. s>0,
2. s consists of n digits,
3. no digit in s equals 0,
4. s is not divisible by any of it's digits.
*/
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>
#define N 5010
using namespace std;
vector<int> numbers;
bool check_zero(long long int number)
{
int zero_flag=0;
while(number !=0){
int temp = number % 10;
number = number/10;
if(temp == 0){
zero_flag = 1;
}
}
if(zero_flag==1){
return true;
}
return false;
}
bool check_digits(long long int number){
int s=number;
while(number > 0) {
int digit=number%10;
// if s is divisible by its digits
if(s%digit==0){
return true;
}
number = number / 10;
}
return false;
}
long long int generate_number(int digits)
{
// 1 <= digits <= 10^5
if(digits==1 || digits>100000 || digits<0){
return -1;
}
else{
long long int lower_limit, upper_limit;
long long int hit=-1;
lower_limit=pow(10,digits-1);
upper_limit=pow(10,digits);
for(int i=lower_limit; i<upper_limit; i++)
{
// check if zero is in the numbers
if(!check_zero(i) && !check_digits(i)){
hit=i;
break;
}
}
return hit;
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int num_test_cases;
cin>>num_test_cases;
// 1 <= num_test_cases <= 400
if(num_test_cases>400 || num_test_cases<0){
cout<<"-1\n";
return 0;
}
for(int i=0; i<num_test_cases; i++)
{
int n;
cin>>n;
numbers.push_back(n);
}
for (int n: numbers)
cout<<generate_number(n)<<endl;
return 0;
}