integer(16) :: n,p,counter,tmp
character(:),allocatable :: s

read *,n,p
allocate(character(n) :: s)
read *,s

counter=0
do il=1,n
	do ir=il,n
    	read(s(il:ir),*) tmp
        if(mod(tmp,p)==0) then
        	counter=counter+1
        end if
    end do
end do

print *,counter
end