Submit | All submissions | Best solutions | Back to list |
ANARC09C - Not So Flat After All |
Any positive integer v can be written as p1a1 * p2a2 *... * pnan where pi is a prime number and ai ≥ 0. For example: 24 = 23 * 31.
Pick any two prime numbers p1 and p2 where p1 != p2. Imagine a two dimensional plane where the powers of p1 are plotted on the x-axis and the powers of p2 on the y-axis. Now any number that can be written as p1a1 * p2a2 can be plotted on this plane at location (x, y) = (a1, a2). The figure shows a few examples where p1 = 3 and p2 = 2.
This idea can be extended for any N-dimensional space where each of the N axes is assigned a unique prime number. Each N-dimensional space has a unique set of primes. We call such set the Space Identification Set or S for short. |S| (the ordinal of S) is N.
Any number that can be expressed as a multiplication of pi ∈ S (each raised to a power (ai ≥ 0) can be plotted in this |S|-Dimensional space. The figure at the bottom illustrates this idea for N = 3 and S = {2, 3, 7}. Needless to say, any number that can be plotted on space A can also be plotted on space B as long as SA ⊂ SB.
We define the distance between any two points in a given N-dimensional space to be the sum of units traveled to get from one point to the other while following the grid lines (i.e. movement is always parallel to one of the axes.) For example, in the figure below, the distance between 168 and 882 is 4.
Given two positive integers, write a program that determines the minimum ordinal of a space where both numbers can be plotted in. The program also determines the distance between these two integers in that space.
Input
Your program will be tested on one or more test cases. Each test case is specified on a line with two positive integers (0 < A, B < 1,000,000) where A * B > 1.
The last line is made of two zeros.
Output
For each test case, print the following line:
k. X:D
Where k is the test case number (starting at one,) X is the minimum ordinal needed in a space that both A and B can be plotted in. D is the distance between these two points.
Example
Input: 168 882 770 792 0 0 Output: 1. 3:4 2. 5:6
Added by: | Mohammad Kotb |
Date: | 2009-11-28 |
Time limit: | 32.12s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 NODEJS OBJC PERL6 SQLITE VB.NET |
Resource: | http://www.icpc-anarc.org |
hide comments
|
||||||
2014-10-16 12:57:01 .::Austin::.
AC at 1st go, 0.01 sec :) Wonder why the given time limit is 60s |
||||||
2013-12-27 08:15:45 Hasil Sharma
@Tjandra : Can you please help me out how were you able to solve it so fast ? even a small hint will be enough. please email me if you can hasilsharma7@gmail.com |
||||||
2013-10-28 20:48:39 BLANKRK
dont knw why 60 sec... :P |
||||||
2013-06-13 11:10:58 Bharath Reddy
Test cases 7778 164 2 1 100 100 Output: 1. 3:3 2. 1:1 3. 2:0 |
||||||
2013-08-21 06:46:42 aqfaridi
i have coded it by seeing 60 sec ... |
||||||
2013-01-28 20:44:39 saket diwakar
really no need of 60seconds....:P |
||||||
2012-12-07 08:55:30 coderred
getting WA again and again someone pls help. |
||||||
2012-06-17 18:13:44 (Tjandra Satria Gunawan)(曾毅昆)
what, 60s time limit???? I can solve this proplem in 0.01s without precomputation and I/O optimization.... |
||||||
2012-04-07 17:56:19 guliashvili
update images please |
||||||
2012-02-15 14:02:13 TLMN
Why I get SIGSEGV ? I downloaded the testdata of the contest and ran well in my computer, but I still get SIGSEGV :-( |