ns = (0..43000).map {|i| [7 * i + 1, 7 * i + 6]}.flatten
ns.delete(1)

primes = []
until ns.empty?
    x = ns[0]
    primes << x
    new_ns = []
    loop do
        y = ns[-1]
        break if y < x * x
        new_ns.unshift y if y % x > 0
        ns.pop
    end
    ns = ns + new_ns
    ns.shift
end

loop do
    n = gets.to_i
    break if n == 1
    puts "#{n}: " + primes.select {|q| n % q == 0} * ' '
end

