GCDGOOD - GCD Goodness
Sankalp's obsession for GCD is increasing day by day. Now he came up with this GCD question.
The goodness of array is defined as the product of sum of all the elements of the array and GCD of all the elements of the array.
In other words goodness of array temp of size k is equal to (temp[1] + temp[2] + ... + temp[k]) * gcd(temp[1], temp[2] ... temp[k]).
In this task you will be given an array and you have to find the sum of goodness of all non-empty subsequences of the given array.
Since the answer can be very large output it modulo 1 000 000 007 (1e9+7).
Definition of: Subsequence
Input
First line of the input is the number of elements in the given array.
Next line contains space separated array elements.
Output
Output the sum of goodness all the non-empty subsequences of the given array modulo 1e9+7.
Constraints
1 ≤ n ≤ 1 000 000
1 ≤ arr[i] ≤ 1 000 000
Example
Input: 4 2 4 6 9 Output: 350
Explanation
There will be 15 non-empty subsequences of the given array given as [2], [4], [6], [9], [2, 4], [2, 6], [2, 9], ... too lazy to write them all :P
Required ans = 2*2 + 4*4 + 6*6 + 9*9 + 6*2 + 8*2 + 11*1 + ... = 350.
Let me know in the comments if it doesn't match :P
Added by: | sankalp_7 |
Date: | 2022-12-05 |
Time limit: | 4s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | Own Problem |