Title:
solution:
观察到n只有1e12,那么最多只有12位,
因此一半最多只有6位,
那么在[0,1e6]内枚举后面一半,计算出整个数x,
如果这个x<=n则ans++.
code:
#include <bits/stdc++.h>
#define int long long
#define PI pair<int,int>
using namespace std;
const int maxm=2e6+5;
int cal(int x){
int ans=0;
while(x){
ans++;
x/=10;
}
return ans;
}
void solve(){
int p[12];
p[0]=1;
for(int i=1;i<=10;i++)p[i]=p[i-1]*10;
int n;cin>>n;
int ans=0;
for(int i=1;i<=1e6;i++){
int len=cal(i);
int t=i*p[len]+i;
if(t<=n)ans++;
else break;
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0);
solve();
return 0;
}