We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
The Chosen One
The Chosen One
Sort by
recency
|
24 Discussions
|
Please Login in order to post a comment
Since I'm in the wedding business, I'm constantly looking for convenient solutions and tools. So, I found this site https://www.quoteroller.com/proposal-templates/wedding-organizer-proposal-template/, which has a lot of great document templates, including the wedding proposal I was looking for. I needed to make the necessary changes, which took me a few minutes, and then I immediately sent the document to the client.
from math import gcd as g n = int(input().strip())
a = list(map(int, input().rstrip().split()))
if len(a) == 1: print(a[0] + 1) else:**
Find the most difficult element. Remove it and calculate gcd of the rest of elemnts.
let X be a set of numbers. let Y be a superset of X (i.e X + {one or more elemnts} ) GCD of Y is less than or equal to GCD of X (more members less common factors, lower gcd)
In the problem,
Iterate and calculate gcd from left to right. Whenever a decline in gcd is observed save that as 'difficult element', continue this (update the 'difficult element' when another decline in gcd is observed - this is a more difficult element than the previous one) towards the end of elements.
So finally we get the most difficult element. If there was no decline in gcd then that means the first element was the most difficult one. Remove that most difficult element and find gcd of the rest of the elemnts in the set. This GCD will not be a divisor of the difficult element. (That is the requirement in the question, find a number which divides all elements except one)
Let the numbers be {a0, a1, a2, ... an} calculate gcd(a0, a1), then gcd(a0, a1, a2), then gcd(a0, a1, a2, a3) ... gcd(a0, a1,...an) whenver new gcd is less than previous gcd, save the elemnt which caused the decline.
Make use of the associative property of GCD i.e
gcd(a0, a1, a2) = gcd(gcd(a0, a1), a2)
gcd(a0, a1, a2, a3) = gcd(gcd(a0, a1, a2), a3)