Under construction

Still being built. Things may change

Bajtemon Collector 2

Time limit4sMemory limit1024 MB

Summary
Each card contributes either its power before or after evolution. Find the largest possible GCD of the chosen powers.
Level

Medium6 of 10

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

Problem

Bajtazar has a huge collection of Bajtemon cards. Each card shows a Bajtemon and lists its power before and after evolution. Bajtazar wants to sell the collection. Under the Bajtocko-Bitocki Agreement on Bajtemon Card Trading, the price of a collection is proportional to the greatest common divisor (GCD) of the powers of all Bajtemons in the deck. The agreement did not account for cards with two powers, so for each card Bajtazar may choose whether to count the power before or after evolution. He wants the GCD to be as large as possible. Write a program that finds the maximum price at which he can sell his collection.

Input

The first line contains an integer nn (1≤n≤1061 \le n \le 10^6), the number of cards. Each of the next nn lines contains two integers aia_i and bib_i (1≤ai≤5⋅1051 \le a_i \le 5 \cdot 10^5, 1≤bi<2631 \le b_i < 2^{63}), separated by a single space. They are the power of the i-th Bajtemon before and after evolution. The power after evolution may be smaller than the power before evolution.

Output

Print one integer, the maximum possible GCD of the Bajtemon powers that Bajtazar can obtain.

Hint

In the example, Bajtazar picks the powers after evolution for the third and fourth Bajtemons, and the powers before evolution for the first and second. The resulting powers are 5, 10, 20, and 5, so their GCD is 5.

Examples1

  1. Example 1

    Input
    4
    5 7
    10 15
    13 20
    7 5
    
    Expected output
    5