ClearAll[DeceptiveNumberQ] DeceptiveNumberQ[n_Integer] := If[! PrimeQ[n], PowerMod[10, n - 1, 9 n] == 1] c = 0; out = Reap[Do[ If[DeceptiveNumberQ[i], Sow[i]; c++; If[c >= 1000, Break[]] ] , {i, 2, \[Infinity]} ]][[2, 1]]; Print["The first 100:"] Multicolumn[Take[out, 100], Appearance -> "Horizontal"] Print["The 1000th is: ", out[[1000]]]