-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecial_Queries.cpp
86 lines (69 loc) · 1.13 KB
/
Special_Queries.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
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
/*
i don't think this is Optimal Approach..xD xD
A number X is special if X is divisible by sum of digits of X. For example 24 is special because it is divisible by 6 (2+4). You are given Q queries where in each query you are given q[i] and you have to report the q[i]th positive special number.
Input
First line of input contains Q. Next Q lines contains q[i].
Constraints :
1 <= Q <= 10000
1 <= q[i] <= 100000
Output
For each query print the q[i]th special number in a new line.
Sample Input
5
1
2
10
11
12
Sample Output
1
2
10
12
18
*/
#include<bits/stdc++.h>
using namespace std;
#define vi vector<ll>
typedef long long ll;
vector<ll> dp(100001 , 0);
ll cal(ll n){
ll res = 0;
while(n){
res += (n % 10);
n /= 10;
}
return res;
}
void solve(){
ll j = 1;
for(ll i = 1 ; i <= 1000000; ++i){
ll rem = cal(i);
if(i % rem == 0){
dp[j++] = i;
if(j == 100000){
return;
}
}
}
}
void solv(){
int n ;
cin >> n;
for(int i = 0 ; i < n ; ++i){
int x;
cin >> x;
cout << dp[x] << "\n";
}
// cout << endl;
}
int main () {
ll tt;
solve();
// cin >> tt;
tt =1;
while(tt--){
solv();
}
return 0;
}