[Solution] Not Adding solution codeforces – Choose two elements from the array 𝑎𝑖ai and 𝑎𝑗aj (𝑖≠𝑗i≠j) such that gcd(𝑎𝑖,𝑎𝑗)gcd(ai,aj) is not present in the array, and add gcd(𝑎𝑖,𝑎𝑗)gcd(ai,aj) to the end of the array.

Not Adding solution codeforces

Not Adding solution codeforces – You have an array 𝑎1,𝑎2,,𝑎𝑛a1,a2,…,an consisting of 𝑛n distinct integers. You are allowed to perform the following operation on it:

  • Choose two elements from the array 𝑎𝑖ai and 𝑎𝑗aj (𝑖𝑗i≠j) such that gcd(𝑎𝑖,𝑎𝑗)gcd(ai,aj) is not present in the array, and add gcd(𝑎𝑖,𝑎𝑗)gcd(ai,aj) to the end of the array. Here gcd(𝑥,𝑦)gcd(x,y) denotes greatest common divisor (GCD) of integers 𝑥x and 𝑦y.

Note that the array changes after each operation, and the subsequent operations are performed on the new array.

What is the maximum number of times you can perform the operation on the array?

Not Adding solution codeforces Input

The first line consists of a single integer 𝑛n (2𝑛1062≤n≤106).

The second line consists of 𝑛n integers 𝑎1,𝑎2,,𝑎𝑛a1,a2,…,an (1𝑎𝑖1061≤ai≤106). All 𝑎𝑖ai are distinct.

Output

Output a single line containing one integer — the maximum number of times the operation can be performed on the given array.

Examples
input

Copy
5
4 20 1 25 30

output Not Adding solution codeforces

3
input

Copy
3
6 10 15
output

Copy
4
Note

In the first example, one of the ways to perform maximum number of operations on the array is:

  • Pick 𝑖=1,𝑗=5i=1,j=5 and add gcd(𝑎1,𝑎5)=gcd(4,30)=2gcd(a1,a5)=gcd(4,30)=2 to the array.
  • Pick 𝑖=2,𝑗=4i=2,j=4 and add gcd(𝑎2,𝑎4)=gcd(20,25)=5gcd(a2,a4)=gcd(20,25)=5 to the array.
  • Pick 𝑖=2,𝑗=5i=2,j=5 and add gcd(𝑎2,𝑎5)=gcd(20,30)=10gcd(a2,a5)=gcd(20,30)=10 to the array.

It can be proved that there is no way to perform more than 33 operations on the original array.

In the second example one can add 33, then 11, then 55, and 22.

Leave a Comment

Your email address will not be published. Required fields are marked *