Hi everybody!
I have been working on the following number problem for half a year, but still unable to figure it out. Could someone help me?
PROBLEM: Given n elements a[1], a[2] ... a[n], let A be a set such that:
All element a[1], a[2] ... a[n] belong to A.
If x, y belong to A, GCD(x, y) and LCM(x, y) belong to A.
Task: Given a number x, determine if x belongs to A.
Thank you.
Auto comment: topic has been updated by duckladydinh (previous revision, new revision, compare).
What are the limits (A[i], n)
1 <= a[i] <= 10^12 1 <= n <= 10^5
if x is gcd of some a[i], then gcd of all a[i] that x divides a[i] is x if x is lcm of some a[i], then lcm of all a[i] that a[i] divides x is x
How about the case that x doesn't divide any a[i] or no a[i] divides x like:
a[1] = 6 = 2 * 3
a[2] = 15 = 3 * 5
a[3] = 77 = 11 * 7
a[4] = 35 = 5 * 7
gcd(6 , 15) = 3 belongs to A
gcd(77, 35) = 7 belongs to A
x = 21 = 3 * 7 belongs to A.
I think gcd case is right.
But lcm case is hacked by your good test case.
What about only focusing on the divisor of x, check them through gcd way & exist in a[i] . And then update in the way of bfs, get lcm of current divisor and previous divisor, add new one to the queue. Check whether x is visited.
I dunno how to prove it, but it seems ...wrong, because I have tried it. :))
http://codeforces.net/blog/entry/17516
Really thank you very much.