中文题意:从1-n挑两个数,加起来后缀9最多。输出有几组。
先根据n判断最多有几个9,明显是以5 50 500来分的界限。
然后从0999,1999,2999,,,,,8999来分别考虑。对每一个算出l和r。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL maxn = 200000+444;
LL a[13];
LL b[13];
void init()
{
a[1]=9;
b[1]=10;
for(LL i=2;i<=12;i++)
a[i]=a[i-1]*10+9,b[i]=b[i-1]*10;
}
LL n;
LL query(LL x,LL pos)
{
LL cnt=x*b[pos]+a[pos];
LL l=max(1LL,cnt-n);
LL r=min(n,cnt-1);
if(l<r) return (r-l+1)/2;
return 0;
}
int main()
{
init();
scanf("%lld",&n);
if(n<=4){
printf("%lld\n",n*(n-1)/2);
}else{
LL now=5;
LL pos=0;
while(n>=now){
pos++;
now*=10;
}
LL ans=0;
for(LL i=0;i<9;i++){
ans+=query(i,pos);
}
printf("%lld\n",ans);
}
return 0;
}