c语言sscanf函数的用法是什么
225
2022-09-16
B. Weakened Common Divisor(筛质因子)
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.
For a given list of pairs of integers (a1,b1)(a1,b1), (a2,b2)(a2,b2), ..., (an,bn)(an,bn) their WCD is arbitrary integer greater than 11, such that it divides at least one element in each pair. WCD may not exist for some lists.
For example, if the list looks like [(12,15),(25,18),(10,24)][(12,15),(25,18),(10,24)], then their WCD can be equal to 22, 33, 55 or 66 (each of these numbers is strictly greater than 11 and divides at least one number in each pair).
You'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.
Input
The first line contains a single integer nn (1≤n≤1500001≤n≤150000) — the number of pairs.
Each of the next nn lines contains two integer values aiai, bibi (2≤ai,bi≤2⋅1092≤ai,bi≤2⋅109).
Output
Print a single integer — the WCD of the set of pairs.
If there are multiple possible answers, output any; if there is no answer, print −1−1.
Examples
input
3 17 18 15 24 12 15
output
6
input
2 10 16 7 17
output
-1
input
5 90 108 45 105 75 40 165 175 33 30
output
5
题目大概:
给出n对数,问是否存在一个数,使得没对数都能找出至少一个数的因子包含该数。
思路:
筛出第一对的质因子,和它本身。
循环暴力判断这些数 是否是剩下的数对的因子。
代码:
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~