Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int q;
- cin >> q;
- while (q --> 0) {
- int n;
- cin >> n;
- if (n == 1) {
- cout << 1 << '\n';
- continue;
- }
- int ans = 0;
- int cur = 0;
- for (int i = 1; i < 10; ++i) {
- for (int j = 1; j <= ceil(log10(n)); ++j) {
- cur += i;
- if (cur <= n) {
- ++ans;
- }
- cur *= 10;
- }
- cur = 0;
- }
- cout << ans << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement