\[Description\]
\[Input/Output\]
\[Sample\]
3
1 5
3 9
8 8
2
2
0
\[Data\ Constraint\]
思路:暴力。
首先我们考虑:
\[D_x=(x-1) \mod 9+1\]
然后再推出一个东西:
\[\text{如果 D(x) 合法,那么 D(x+k) 肯定合法}\]
\[k=LCM(1,2,3,4,5,6,7,8,9,10)=22680\]
预处理 \(1\)~\(k\) 的合法个数,查询的时候直接前缀和一下。
时间复杂度: \(O(Tk)\)
Const node_num=22680;
var
bucket:array[-1..node_num] of boolean;
tmp,test:longint;
l,r:int64;
function D(x:int64):int64; begin exit((x-1) mod 9+1); end;
procedure Init;
var i:longint;
begin
fillchar(bucket,sizeof(bucket),True);
for i:=1 to node_num do if (i*D(i)<=node_num)and(bucket[i*D(i)]) then
begin
inc(tmp); bucket[i*D(i)]:=False;
end;
end;
function Slove(x:int64):int64;
var i:longint;
begin
Slove:=0;
for i:=1 to x mod node_num do if bucket[i]=False then inc(Slove);
inc(Slove,x div node_num*tmp);
end;
begin
Init; read(test);
while test>0 do
begin
read(l,r); dec(test);
writeln(Slove(r)-Slove(l-1));
end;
end.