### constant

MAX_N = 300000

### subroutines

def msnum_generator(max_n)
  yield 6
  k = 7
  loop do
    n = k + 1
    break if n > max_n
    yield n

    n = k + 6
    break if n > max_n
    yield n

    k += 7
  end
end

def gen_msprimes(max_p, msnums)
  msprimes = (max_p + 1).times.map{false}
  msnums.each{|msn| msprimes[msn] = true}

  msps = []

  for p in msnums
    if msprimes[p]
      msps << p
      for q in msnums
        pq = p * q
        break if pq > max_p
        msprimes[pq] = false
      end
    end
  end

  msps
end

### main

msnums = []
msnum_generator(MAX_N){|msn| msnums << msn}
#p msnums

msps = gen_msprimes(MAX_N, msnums)

loop do
  n = gets.to_i
  break if n == 1

  msds = []

  for msp in msps
    if n % msp == 0
      n17 = (n / msp) % 7
      if n17 == 1 || n17 == 6
        msds << msp
      end
    end
  end

  puts "#{n}: " + msds.join(' ')
end