-
Notifications
You must be signed in to change notification settings - Fork 0
/
1520B.cpp
47 lines (37 loc) · 830 Bytes
/
1520B.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
/**
* 1520B - https://codeforces.com/contest/1520/problem/B
*
* Code by @trhgquan - https://github.com/trhgquan
*/
#include<bits/stdc++.h>
#define longint int64_t
using namespace std;
longint buildNumber(int max) {
stringstream builder;
int current = 0;
while (current < max) {
builder << 1;
++current;
}
return stoi(builder.str());
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
// Solution goes here.
int t; cin >> t;
while (t--) {
longint n; cin >> n;
int res = 0;
for (int i = 1; i <= 9; ++i) {
longint currentNum = buildNumber(i);
for (int j = 1; j <= 9; ++j) {
longint current = currentNum * j;
if (current <= n) ++res;
else break;
}
if (currentNum > n) break;
}
cout << res << '\n';
}
return 0;
}