sub f{($d=$d[$_])**$n*$d>$x?last:$x%$d||f(local$x=$x/$d)for$_..@d*--$n;$%+=!$n++}$x=<>=~$"+$';@d=grep$x%$_<1,2..4e4;print f$n=$`