#GL0000391. Kho báu GCD (GCD Treasury)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Kho báu GCD (GCD Treasury)
GCD Treasury
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are coin piles; pile initially has coins. A pirate holds a positive integer . At each step, choose a nonempty pile with , remove exactly coins from that pile and replace by . The process stops when no eligible pile remains.
You may choose the piles in any order and revisit the same pile. Find the maximum total number of coins removed.
Input
The first line contains . The second contains . PHOJ uses one case per file instead of the original Codeforces multi-case wrapper.
Output
Print the maximum total number of removed coins.
Subtasks
-
Subtask 1 (20 points): , .
-
Subtask 2 (30 points): , .
-
Subtask 3 (50 points): .
Examples
Example 1
Input
3 4
2 3 4
Output
6
Explanation
Take coins from the last pile, leaving , then from the first pile, leaving . The remaining pile contains coins but , so the total is .
Example 2
Input
4 2
2 2 2 2
Output
8
Explanation
Every pile is divisible by and may be emptied. Each step keeps ; four piles contribute eight coins.