http://www.lydsy.com/JudgeOnline/problem.php?id=2405
神题
首先可以发现D(x)=(x-1)%9+1
然后发现、、如果x是个合法的数字,那么x+22680也是
22680=lcm(1,2,3..9)*9
于是暴力预处理出a[i]表示1~i中合法数字个数,然后询问x可以转化为
a[22680]*(x/22680)+a[x%22680]
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,j,k) for(int i=j;i<=k;++i)
#define Dow(i,j,k) for(int i=k;i>=j;--i)
#define ll long long
using namespace std;
inline ll read()
{
ll t=0,f=1;char c=getchar();
while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9')t=t*10+c-48,c=getchar();
return t*f;
}
int a[30001];
ll n,L,R;
inline void pre()
{
For(i,1,22680)
if(i*((i-1)%9+1)<=22680) a[(i*((i-1)%9+1))]=1;
For(i,1,22680) a[i]+=a[i-1];
}
inline ll get(ll x)
{
if(x==-1) return 0;
return 1LL*a[22680]*(x/22680LL)+a[x%22680];
}
int main()
{
pre();
n=read();
For(i,1,n)
{
L=read();R=read();
printf("%lld\n",get(R)-get(L-1));
}
}