require "bignum" local fmt = require "fmt" local rd = {"22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"} mpz.init() -- use GMP mpz.convert(false) -- leave results as strings for i = 2, 9 do fmt.print("First 10 super-%d numbers:", i) local count = 0 local j = 3 local k while count < 10 do local a = mpz.set(1, j) mpz.pwr(a, i) k = mpz.mul(a, i, true) local ix = k:find(rd[i - 1], 1, true) if ix then count += 1 fmt.write("%s ", j) end j += 1 end print("\n") end mpz.clearAll(false)