Not So Flat After All

Time limit1sMemory limit128 MB

Summary
For each pair of positive integers, find the smallest prime set covering both numbers and the Manhattan distance between their exponent vectors.
Level

Medium4 of 10

Topics
Number theory, Math, Implementation
Solved
No attempts yet

Problem

Every positive integer vv can be written as v=p1a1⋅p2a2⋯pnanv = p_1^{a_1} \cdot p_2^{a_2} \cdots p_n^{a_n}, where each pip_i is a prime and every ai≥0a_i \ge 0. For example, 24=23⋅3124 = 2^3 \cdot 3^1.

Pick two distinct primes p1≠p2p_1 \ne p_2. Consider a two-dimensional plane on which the exponent of p1p_1 is the x-coordinate and the exponent of p2p_2 is the y-coordinate. Any number of the form p1a1⋅p2a2p_1^{a_1} \cdot p_2^{a_2} is then the point (a1,a2)(a_1, a_2).

This idea extends to any NN-dimensional space in which each of the NN axes is assigned a distinct prime. Every such space has a unique set of primes, which we call the Space Identification Set SS; its size ∣S∣|S| equals NN. Any number that is a product of primes taken only from SS (each raised to an exponent ≥0\ge 0) can be plotted in this ∣S∣|S|-dimensional space. Naturally, any number plottable in space AA is also plottable in space BB whenever SA⊆SBS_A \subseteq S_B.

The distance between two points is the number of unit steps needed to travel from one to the other along the grid lines, where every move is parallel to a single axis. This equals the Manhattan (L1) distance between the two coordinate vectors. For instance, 168=23⋅3⋅7168 = 2^3 \cdot 3 \cdot 7 and 882=2⋅32⋅72882 = 2 \cdot 3^2 \cdot 7^2 are at distance ∣3−1∣+∣1−2∣+∣1−2∣=4|3-1| + |1-2| + |1-2| = 4.

Given two positive integers, determine the minimum size of a space in which both numbers can be plotted, and the distance between the two numbers in that space.

Input

The input contains one or more test cases. Each test case is a single line with two positive integers AA and BB (0<A,B<1,000,0000 < A, B < 1{,}000{,}000) satisfying A⋅B>1A \cdot B > 1. The input ends with a line containing two zeros, which must not be processed.

Output

For each test case, print one line in the form:

k. X:D

where kk is the test case number (starting from 1), XX is the minimum size of a space in which both AA and BB can be plotted, and DD is the distance between the two numbers in that space.

Examples3

  1. Example 1

    Input
    168 882
    770 792
    0 0
    
    Expected output
    1. 3:4
    2. 5:6
    
  2. Example 2

    Input
    2 3
    0 0
    
    Expected output
    1. 2:2
    
  3. Example 3

    Input
    8 32
    0 0
    
    Expected output
    1. 1:2