def A(x):
  if x % 2 == 0 or x % 5 == 0:
    return -1
  n = 0
  num = 0
  while 1:
    n = (n * 10 + 1) % x
    num += 1
    if n == 0:
      return num

maxx = 10 ** 9

P = [2]
p = [2]
n = 3
out = []
while len(out) < 40:
  for i in p:
    if n % i == 0:
      break
  else:
    P.append(n)
    tmp = A(n)
    if tmp > 0:
      if maxx % tmp == 0:
        out.append(n)
  n += 2
  while n > p[-1] ** 2:
    p.append(P[len(p)])

print sum(out), out