Divide and Conquer

Time limit1sMemory limit128 MB

Summary
Among integers from M to N, pick the one with the most divisors, breaking ties by the largest value, and report it with its divisor count.
Level

Easy3 of 10

Topics
Number theory, Brute force, Implementation, Math
Solved
No attempts yet

Problem

You are given two integers MM and NN with 1≤M≤N≤50001 \le M \le N \le 5000. Determine two integers XX and YY that satisfy all of the following:

  • A. M≤X≤NM \le X \le N;
  • B. YY is the number of divisors of XX;
  • C. YY is as large as possible;
  • D. XX is as large as possible.

In other words, among all integers in the range [M,N][M, N], choose the one with the greatest number of divisors as XX; if several integers tie for the greatest number of divisors, choose the largest such integer. YY is that number of divisors.

Input

The input consists of several test cases. Each test case is a single line containing two integers MM and NN (1≤M≤N≤50001 \le M \le N \le 5000) separated by a space. A line with M=N=0M = N = 0 marks the end of the input and should not be processed.

The input is read from standard input.

Output

For each test case, print a single line containing the two integers XX and YY separated by a space.

The output is written to standard output.

Examples1

  1. Example 1

    Input
    1 5
    300 500
    4500 5000
    0 0
    
    Expected output
    4 3
    480 24
    4680 48