awk '
NR==1{n=$1; p=$2}
NR==2{s=$1}
END{
  c = 0
  for(i=1; i <= length(s); i++) {
    for(j=1; j <= length(s) - i + 1; j++) {
      ss = substr(s, i, j)
      print "echo",ss,"%",p,"|bc"
    }
  }
}
' | sh | grep -c ^0$
