大水题
就看每个范围内有多少个每一位都相同的数
长度为j
的每一位都是i的数的公式为:
(
p
o
w
(
10
,
j
)
−
1
)
/
9
∗
i
(pow(10, j)-1)/9 *i
(pow(10,j)−1)/9∗i
每次最多计算
O
(
9
∗
9
∗
9
)
O(9*9*9)
O(9∗9∗9)次,一共计算
1
0
4
∗
9
∗
9
∗
9
10^4*9*9*9
104∗9∗9∗9次
// Problem: B. Ordinary Numbers
// Contest: Codeforces - Codeforces Round #719 (Div. 3)
// URL: https://codeforces.com/problemset/problem/1520/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Code by: ING__
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"
using namespace std;
typedef pair<int, int> PII;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
int T;
int n;
int pow1(int n){
int res = 1;
while(n--){
res *= 10;
}
return res;
}
int main(){
cin >> T;
while(T--){
cin >> n;
ll ans = 0;
for(int i = 1; i <= 9; i++){
for(int j = 1; j <= 9; j++){
int t = pow1(j);
int x = (t - 1) / 9;
if(x * i <= n){
// cout << x * i << endl;
ans++;
}
else break;
}
}
cout << ans << Endl;
}
re 0;
}