Monday-Saturday Numbers

Time limit2sMemory limit128 MB

Summary
For each number, list the Monday-Saturday numbers that are irreducible divisors within the set of integers congruent to 1 or 6 mod 7.
Level

Medium6 of 10

Topics
Number theory, Math, Implementation
Solved
No attempts yet

Problem

An integer that leaves a remainder of 11 or 66 when divided by 77 is called a 7N+{1,6}7N + \{1, 6\} number. Because that name is awkward, we will call such an integer a Monday-Saturday number.

For two Monday-Saturday numbers aa and bb, if there exists a Monday-Saturday number xx such that ax=ba x = b, then aa is called a Monday-Saturday divisor of bb. In fact, if a Monday-Saturday number aa divides bb in the ordinary sense, then aa is a Monday-Saturday divisor of bb, and the converse also holds.

A Monday-Saturday prime is a Monday-Saturday number greater than 11 that has no Monday-Saturday divisors other than 11 and itself. If a Monday-Saturday number is prime in the ordinary sense, then it is a Monday-Saturday prime; however, the converse does not hold. For example, 2727 is a Monday-Saturday prime but is not an ordinary prime.

Among the Monday-Saturday divisors of a Monday-Saturday number, those that are Monday-Saturday primes are called its Monday-Saturday prime factors. For example, 2727 is a Monday-Saturday prime factor of 216216 (since 216=27×8216 = 27 \times 8).

Every Monday-Saturday number greater than 11 can be written as a product of one or more Monday-Saturday primes, but this representation is not unique. For example, 216=6×6×6=8×27216 = 6 \times 6 \times 6 = 8 \times 27.

Given a Monday-Saturday number, write a program that finds all of its Monday-Saturday prime factors.

Input

The input consists of several test cases. Each test case is a single line containing one Monday-Saturday number. This number is greater than 11 and less than 300000300000. The last line of the input contains 11, which should not be processed.

Output

For each test case, print the given Monday-Saturday number followed by :, and then print its Monday-Saturday prime factors in ascending order. Print a single space before each Monday-Saturday prime factor.

Examples3

  1. Example 1

    Input
    205920
    262144
    262200
    279936
    299998
    1
    
    Expected output
    205920: 6 8 13 15 20 22 55 99
    262144: 8
    262200: 6 8 15 20 50 57 69 76 92 190 230 475 575 874 2185
    279936: 6 8 27
    299998: 299998
    
  2. Example 2

    Input
    6
    8
    13
    15
    1
    
    Expected output
    6: 6
    8: 8
    13: 13
    15: 15
    
  3. Example 3

    Input
    20
    22
    27
    29
    1
    
    Expected output
    20: 20
    22: 22
    27: 27
    29: 29