Not So Flat After All
Time limit1sMemory limit128 MB
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 can be written as , where each is a prime and every . For example, .
Pick two distinct primes . Consider a two-dimensional plane on which the exponent of is the x-coordinate and the exponent of is the y-coordinate. Any number of the form is then the point .
This idea extends to any -dimensional space in which each of the axes is assigned a distinct prime. Every such space has a unique set of primes, which we call the Space Identification Set ; its size equals . Any number that is a product of primes taken only from (each raised to an exponent ) can be plotted in this -dimensional space. Naturally, any number plottable in space is also plottable in space whenever .
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, and are at distance .
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 and () satisfying . 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 is the test case number (starting from 1), is the minimum size of a space in which both and can be plotted, and is the distance between the two numbers in that space.