var
i,n,m,k,l,r:longint;
sv:text;
begin
assign(sv,'C:\Users\Administrator\Desktop\Data\Data1.in'); rewrite(sv);
randomize;
n:=100; m:=100; k:=11; writeln(sv,n,' ',m,' ',k);
for i:=1 to n do write(sv,random(n)+1,' '); writeln(sv);
for i:=1 to m do
begin
r:=random(n)+1; l:=random(r)+1;
writeln(sv,l,' ',r);
end;
close(sv);
end.
---
Const
total=1000;
var
num:array[-1..total] of longint;
l,r,i,j,p,k,n,m,ans:longint;
begin
read(n,m,p);
for i:=1 to n do read(num[i]);
for k:=1 to m do
begin
read(l,r); ans:=0;
for i:=l to r do for j:=l to r do if num[i] mod num[j]=p then inc(ans);
writeln(ans);
end;
end.
Uses math;
Const
total=10000 << 1+10;
block_sum=total*trunc(sqrt(total >> 1))+10;
var
pom,next,reach:array[-1..block_sum] of longint;
num,ans,bucket:array[-1..total] of longint;
ele:array[1..6,-1..total] of longint;
cnt:array[-1..total] of longint;
n,m,k,i,j,l,r,tot,maxn,node_num,block_num:longint;
procedure Swap(var x,y:longint);var t:longint; begin t:=x; x:=y; y:=t; end;
function Locate(node:longint):longint;
begin
if node mod node_num=0 then exit(node div node_num);
exit(node div node_num+1);
end;
procedure Link(l,r,id:longint);
begin
inc(tot); reach[tot]:=r; pom[tot]:=id;
next[tot]:=cnt[l]; cnt[l]:=tot;
end;
procedure Sort(l,r,a,b,c,d:longint);
var i,j,s1,s2:longint;
begin
i:=l; j:=r; s1:=ele[a,(l+r) >> 1]; s2:=ele[b,(l+r) >> 1];
repeat
while (ele[a,i]<s1)or((ele[a,i]=s1)and(ele[b,i]<s2)) do inc(i);
while (ele[a,j]>s1)or((ele[a,j]=s1)and(ele[b,j]>s2)) do dec(j);
if i<=j then
begin
Swap(ele[a,i],ele[a,j]); Swap(ele[b,i],ele[b,j]);
Swap(ele[c,i],ele[c,j]); Swap(ele[d,i],ele[d,j]); inc(i); dec(j);
end;
until i>=j; if i<r then Sort(i,r,a,b,c,d); if j>l then Sort(l,j,a,b,c,d);
end;
procedure Tansfer(l,r,x,id,mode:longint);
var a,b:longint;
begin
if mode=1 then begin a:=1; b:=-1; end else begin a:=-1; b:=1; end;
Link(r,x,a*id); Link(l-1,x,b*id);
end;
procedure Moheader;
var i,j:longint;
begin
filldword(cnt,sizeof(cnt) >> 2,maxlongint << 1+1);
read(n,m,k); node_num:=trunc(sqrt(n)); block_num:=Locate(n);
for i:=1 to n do begin read(num[i]); maxn:=max(maxn,num[i]); end;
for i:=1 to m do begin read(ele[1,i],ele[2,i]); ele[4,i]:=Locate(ele[1,i]); ele[3,i]:=i; end;
Sort(1,m,4,2,1,3); l:=1; r:=0;
for i:=1 to m do
begin
while r<ele[2,i] do begin inc(r); Tansfer(l,r-1,num[r],ele[3,i],1); end;
while r>ele[2,i] do begin Tansfer(l,r-1,num[r],ele[3,i],-1); dec(r); end;
while l<ele[1,i] do begin Tansfer(l+1,r,num[l],ele[3,i],-1); inc(l); end;
while l>ele[1,i] do begin dec(l); Tansfer(l+1,r,num[l],ele[3,i],1); end;
end;
end;
procedure Cfunction_make;
var i,j,t,anss,zero:longint;
begin
for i:=1 to maxn do bucket[i]:=0; zero:=0;
for i:=1 to n do
begin
if num[i]=k then inc(zero);
if num[i]>k << 1 then
begin
t:=num[i]-k;
for j:=2 to trunc(sqrt(t)) do begin if t mod j<>0 then continue; inc(bucket[j]); inc(bucket[t div j]); end;
if sqrt(t)=trunc(sqrt(t)) then dec(bucket[trunc(sqrt(t))]); inc(bucket[t]);
end;
j:=cnt[i];
while j<>-1 do
begin
if reach[j]>k then inc(ans[abs(pom[j])],(pom[j] div abs(pom[j]))*(bucket[reach[j]]+zero));
j:=next[j];
end;
end;
end;
procedure Dfunction_make;
var i,j,t:longint;
begin
for i:=1 to maxn do bucket[i]:=0;
for i:=1 to n do
begin
if num[i]>k then
begin
t:=num[i];
for j:=0 to trunc(maxn/t+1) do begin if t*j+k>maxn then break; inc(bucket[t*j+k]); end;
end;
j:=cnt[i];
while j<>-1 do
begin
inc(ans[abs(pom[j])],(pom[j] div abs(pom[j]))*(bucket[reach[j]]));
j:=next[j];
end;
end;
end;
begin
Moheader;
Cfunction_make;
Dfunction_make;
for i:=1 to m do begin inc(ans[ele[3,i]],ans[ele[3,i-1]]); end;
for i:=1 to m do writeln(ans[i]);
end.