Блог пользователя xennygrimmato

Автор xennygrimmato, 10 лет назад, По-английски

Q: Given an array of n integers, find the maximum value of GCD for all possible pairs.

Sample Test Case- 1 2 3 4 5 Output: 2

2<=n<=10^5

Теги gcd
  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
10 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Take a look at this post.

»
10 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Mark all divisors of each element, in O(sqrt(n)). Then find maximum element of mark array that is marked more than twice, in O(n).

»
10 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

If you are referring to the problem from the yesterday contest on CodeChef, I got AC in O(MaxA * log(MaxA)) by trying all possible GCDs and seeing if there are at least two numbers that divide it, same as mentioned in the post (link given in the first comment). However, it required some optimization to actually fit it into the TL (Like clearing the array of used digits in O(N) rather than in O(MaxA).). I wonder if there is a solution that doesn't depend on the values of numbers and is fast enough.

»
7 лет назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

This question is close with HackerRank WoC 34 #2 (https://www.hackerrank.com/contests/w34/challenges/maximum-gcd-and-sum), please don't answer comments like written today and from "fake" accounts till end of competition. However, there is answer in comments...

Good luck