Ananya Pandey At Kapil Sharma Show

0

0 votes
GCD, 1-D, Arrays, Hashing, Math Basic
Problem

One day Ananya Pandey arrives at Kapil Sharma Show for the promotion of movie "Student of the year 2".As Kapil always makes fun of everyone So Ananya decided to make fun of Kapil sharma this time.She gives an array of N integers to Kapil and wants the summation of GCD of all subarray. 

i=1N j=iNGCD(i...j)

Here, GCD denotes the greatest common divisor of a set of numbers and GCD(i...j)=GCD(i,i+1,i+2.......j1,j)

GCD(K,K)=GCD(0,K)=GCD(K,0)=K.

This summation may be very large so take modulo with (109+7).
As you know Kapil Sharma is weak in Math So he needs your Help!!!

Input
First line contains a single Integer N(1<=N<=105), length of array
Second line contains N integers, xi (1<=xi<=1012)represents ith element in array.

Output
A single Integer i.e. summation of GCD of all subarray modulo (109+7).

Sample Input
4
5 15 10 20
Sample Output
85
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

GCD(1...1)=5,GCD(1...2)=5,GCD(1...3)=5,GCD(1...4)=5,

GCD(2...2)=15,GCD(2...3)=5,GCD(2...4)=5,

GCD(3...3)=10,GCD(3...4)=10,

GCD(4...4)=20

(5+5+5+5+15+5+5+10+10+20) % (109+7)=85

Editor Image

?