{"problem":{"name":"B. Weakened Common Divisor","description":{"content":"During the research on properties of the greatest common divisor (_GCD_) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (_WCD_) of a ","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF1025B"},"statements":[{"statement_type":"Markdown","content":"During the research on properties of the greatest common divisor (_GCD_) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (_WCD_) of a list of pairs of integers.\n\nFor a given list of pairs of integers $(a_1, b_1)$, $(a_2, b_2)$, ..., $(a_n, b_n)$ their _WCD_ is arbitrary integer greater than $1$, such that it divides at least one element in each pair. WCD may not exist for some lists.\n\nFor example, if the list looks like $[(12, 15), (25, 18), (10, 24)]$, then their WCD can be equal to $2$, $3$, $5$ or $6$ (each of these numbers is strictly greater than $1$ and divides at least one number in each pair).\n\nYou're currently pursuing your PhD degree under Ildar's mentorship, and that's why this problem was delegated to you. Your task is to calculate _WCD_ efficiently.\n\n## Input\n\nThe first line contains a single integer $n$ ($1 \\le n \\le 150\\,000$) — the number of pairs.\n\nEach of the next $n$ lines contains two integer values $a_i$, $b_i$ ($2 \\le a_i, b_i \\le 2 \\cdot 10^9$).\n\n## Output\n\nPrint a single integer — the _WCD_ of the set of pairs.\n\nIf there are multiple possible answers, output any; if there is no answer, print $-1$.\n\n[samples]\n\n## Note\n\nIn the first example the answer is $6$ since it divides $18$ from the first pair, $24$ from the second and $12$ from the third ones. Note that other valid answers will also be accepted.\n\nIn the second example there are no integers greater than $1$ satisfying the conditions.\n\nIn the third example one of the possible answers is $5$. Note that, for example, $15$ is also allowed, but it's not necessary to maximize the output.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"在研究一组数的最大公约数（_GCD_）性质时，著名数学家 Ildar 引入了一个全新的概念——整数对列表的弱公约数（_WCD_）。\n\n对于给定的整数对列表 $(a_1, b_1)$, $(a_2, b_2)$, ..., $(a_n, b_n)$，其 _WCD_ 是任意一个大于 $1$ 的整数，使得它能整除每一对中的至少一个元素。某些列表可能不存在 WCD。\n\n例如，如果列表为 $[ (12, 15), (25, 18), (10, 24) ]$，则其 WCD 可以为 $2$、$3$、$5$ 或 $6$（这些数均严格大于 $1$，且能整除每一对中的至少一个数）。\n\n你目前正在 Ildar 的指导下攻读博士学位，因此这个问题被交由你来解决。你的任务是高效地计算 _WCD_。\n\n第一行包含一个整数 $n$（$1 lt.eq n lt.eq 150 thin 000$）——表示对的数量。\n\n接下来的 $n$ 行，每行包含两个整数 $a_i$、$b_i$（$2 lt.eq a_i, b_i lt.eq 2 dot.op 10^9$）。\n\n请输出一个整数——该整数对集合的 _WCD_。\n\n如果存在多个可能的答案，请输出任意一个；如果不存在答案，请输出 $-1$。\n\n在第一个例子中，答案为 $6$，因为它能整除第一对中的 $18$、第二对中的 $24$ 和第三对中的 $12$。注意，其他合法答案也会被接受。\n\n在第二个例子中，不存在满足条件的大于 $1$ 的整数。\n\n在第三个例子中，一个可能的答案是 $5$。注意，例如 $15$ 也是允许的，但无需最大化输出。\n\n## Input\n\n第一行包含一个整数 $n$（$1 lt.eq n lt.eq 150 thin 000$）——表示对的数量。接下来的 $n$ 行，每行包含两个整数 $a_i$、$b_i$（$2 lt.eq a_i, b_i lt.eq 2 dot.op 10^9$）。\n\n## Output\n\n请输出一个整数——该整数对集合的 _WCD_。如果存在多个可能的答案，请输出任意一个；如果不存在答案，请输出 $-1$。\n\n[samples]\n\n## Note\n\n在第一个例子中，答案为 $6$，因为它能整除第一对中的 $18$、第二对中的 $24$ 和第三对中的 $12$。注意，其他合法答案也会被接受。在第二个例子中，不存在满足条件的大于 $1$ 的整数。在第三个例子中，一个可能的答案是 $5$。注意，例如 $15$ 也是允许的，但无需最大化输出。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of pairs.  \nLet $ P = \\{(a_i, b_i) \\mid i \\in \\{1, \\dots, n\\}\\} $ be a set of pairs of integers, where $ a_i, b_i \\geq 2 $.\n\nA **weakened common divisor (WCD)** of $ P $ is an integer $ d > 1 $ such that for every pair $ (a_i, b_i) \\in P $, either $ d \\mid a_i $ or $ d \\mid b_i $.\n\n**Constraints**  \n1. $ 1 \\leq n \\leq 150{,}000 $  \n2. $ 2 \\leq a_i, b_i \\leq 2 \\times 10^9 $ for all $ i \\in \\{1, \\dots, n\\} $\n\n**Objective**  \nFind any integer $ d > 1 $ such that $ d \\mid a_i $ or $ d \\mid b_i $ for all $ i \\in \\{1, \\dots, n\\} $.  \nIf no such $ d $ exists, output $ -1 $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF1025B","tags":["brute force","greedy","number theory"],"sample_group":[["3\n17 18\n15 24\n12 15","6"],["2\n10 16\n7 17","\\-1"],["5\n90 108\n45 105\n75 40\n165 175\n33 30","5"]],"created_at":"2026-03-03 11:00:39"}}