#Python 2, 74 bytes Having already been soundly beaten by @Flp.Tkc I'll just post my 74 byte recursive solution because it's different and it works and not because it will win (and also because I like recursive functions). def f(a,b,c=1): print(`c`,"Shaggy")[c%b<1or`b`in`c`] if c<a:f(a,b,c+1) **From comments:** Call using f(a,b) c will default to 1 due to the c=1 in the function definition and can then be incremented for the recursive function calls.