report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
GGCD - FlandreOJ: Flandre Online Judge

GGCD

Time limit: 1000 ms
Memory limit: 256 MB
For a sequence $a$ consisting of $n$ non-negative elements, replace one element in the sequence $a$ with another non-negative integer such that the greatest common divisor (GCD) of all elements in $a$ is maximized. ### Input - The first line contains an integer $n$. - The second line contains $n$ integers $a_i$. ### Output - Print a single integer, which is the maximum possible GCD of the elements in $a$. ### Constraints - $1 \le n \le 10^5$. - $1 \le a_i \le 10^9$. ### Example Input: ``` 3 4 2 8 ``` Output: ``` 4 ``` Explanation: - Replace the element $2$ with $12$, the GCD of $4$, $12$, and $8$ is $4$.
Basic number theory
Prime number 2
Sieve of Eratosthenes
Segmented sieve
Prime factors
Maximum GCD
Divisors counting
Largest common divisor
Nearest Element
Divisors counting 2
GCD and LCM
GGCD
Square root sum
Square number
Sum sum sum
Topic
Math
Rating 1200
Solution (1) Solution