Doubled GCD
Time limit2sMemory limit1024 MB
Given N numbers, repeatedly replace two cards x and y with 2 * gcd(x, y) until one card is left, and find the largest possible final value.
- Level
Medium6 of 10
- Topics
- Number theory, Math, Bit manipulation
- Solved
- No attempts yet
Problem
There are cards in a deck, numbered from 1 to . Card has a positive integer written on it.
You perform moves with the cards. In each move, you select two cards from the deck. Let and be the integers on the selected cards. Remove both cards and insert a new card with written on it, where is the greatest common divisor of and . Each move leaves one fewer card in the deck, since two cards are removed and one is inserted.
After all moves, exactly one card remains. Find the maximum possible integer on the last card and output it.
Input
The first line contains an integer (), the number of cards. The next line contains integers (), where is the number written on card .
Output
Output the maximum possible integer on the last card on a single line.