#!/bin/bash

f(){
seq 0 NaN|sed -r "h;/[12357]/d;s/8|0/&&/g;/^.{$1}/!d;x"|sed $2!d\;q
}

for t in "1 5" "2 5"; do
	f $t
done