(tolerance) Codeforces Round #428 (Div. 2) D. Winter is here

Source: Internet
Author: User
Tags gcd greatest common divisor

D. Winter is heretime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Winter is, and the white Walkers is close. John Snow has a army consisting of n soldiers. While the rest of the world was fighting for the Iron Throne, he was going to get ready for the attack of the white Walkers.

He has created a method to know how strong He army is. Let theI-th soldier ' s strength beaI. For somekHe callsI1,?I2,?...,?IkA clan IfI1?<? I 2?<? I 3?<?...? <? I K and gcd ( a I 1,? a i 2,?...,? A i K )? >?1. He calls the strength of that clan k GCD ( a i 1,? A i 2,?...,? A i K ). Then he defines the strength of him army by the sum of strengths in all possible clans.

Your task is to find the strength of he army. As the number may is very large, you have to print it modulo 1000000007 (9?+?7).

Greatest common divisor (GCD) of a sequence of integers is the maximum possible integer so, each element of the Sequen Ce is divisible by it.

Input

The first line contains integer n (1?≤? n? ≤?200000)-the size of the army.

The second line contains n integers a1,? A2,?...,? An (1?≤? ) Ai≤?1000000)-denoting the strengths of his soldiers.

Output

Print one integer-the strength of John Snow ' s army modulo 1000000007 (9?+?7).

Examplesinput
3
3 3 1
Output
12
Input
4
2 3 4 6
Output
39
Note

In the first sample the Clans is {1},?{ 2},? {1,?2} So the answer would be 1 3?+?1 3?+?2 3?=?12

It is similar to a problem-solving approach that preceded a number of schools this year. Consider each GCD, if a sequence satisfies gcd to divide each number of the sequence, then the GCD must divide the true maximum common factor of the sequence. For a number x, it is much easier to find the sequence of each number in an X-divisible sequence than the number of sequences in which X is a sequence gcd, and they are related, so we first find out the number of sequences for each number in each x, divisible sequence. It is obvious that the number in the sequence must be selected from the number divisible by x, with CNT, the number of series is

The following calculation of the sequence of GCD using a strategy from the back-to-front, so that you can effectively avoid the trouble of their own positive sequence write, because we have to seek from the back to the current number of orders is to ensure that the number of gcd exactly for this sequence number, not currently available x corresponds to the sequence gcd is x,2*x,3*x ... The sum of the number of, just want to get the part that has been calculated to lose all, the GCD is the number of x sequence.

1#include <cstdio>2#include <iostream>3#include <algorithm>4#include <vector>5#include <Set>6#include <map>7#include <string>8#include <cstring>9#include <stack>Ten#include <queue> One#include <cmath> A#include <ctime> -#include <bitset> -#include <utility> the using namespacestd; - #defineREP (I,n) for (i=0;i<n;i++) - #defineRrep (I,n) for (i=n-1;i>=0;i--) - #defineRep (I,s,n) for (i=s;i<n;i++) + #defineRrep (I,s,n) for (i=n-1;i>=s;i--) - #definefor (I,s,n) for (i=s;i<=n;i++) + #defineRfor (I,s,n) for (i=n;i>=s;i--) A #defineRank RANKK at #defineDFT FFT -typedef unsignedLong Longull; -typedefLong Longll; - Const intinf=0x3f3f3f3f; - Constll inff=0x3f3f3f3f3f3f3f3fll; - //const LL m=1e9+7; in Constll maxn=2e5+7; - Const intmaxn=1005; to Const intmax=1e6+5; + Const intmax_n=MAX; - Const intn= -; the Constll mod=1e9+7; * //const double eps=0.00000001; $ intgcdintAintb) {returnB?GCD (b,a%b): A;}Panax NotoginsengTemplate<typename T>inline T ABS (t a) {returnA>0? a:-A;} - Inline ll powmm (ll a,ll b,ll M) { thell ret=1; +a%=M; A //b%=m; the      while(b) { +         if(b&1) ret=ret*a%M; -b>>=1; $a=a*a%M; $     } -     returnret; - } the voidOpen () - {WuyiFreopen ("1004.in","R", stdin); theFreopen ("OUT.txt","W", stdout); - } Wu intN; - intNum[max],tem,cnt[max],who,ans[max]; About intan ; $ Set<int>s; - Set<int>:: iterator it; - intMain () - { Ascanf"%d",&n); +      for(intI=1; i<=n;i++) the     { -scanf"%d",&tem); $num[tem]++; the S.insert (TEM); the     } the      for(It=s.begin (); It!=s.end (); it++) the     { -who=*it; in          for(intI=1; i*i<=who;i++) the         { the             if(who%i==0) About             { thecnt[i]+=num[who]; the                 if(i*i!=Who ) thecnt[who/i]+=num[who]; +             } -         } the     }Bayi //printf ("who=%d\n", who); the      for(intj=who;j>=2; j--) the     { - //printf ("~~%d%d\n", J,cnt[j]); -         if(!Cnt[j]) the             Continue; theans[j]= (LL) powmm (2LL, (LL) cnt[j]-1, MOD) *cnt[j]%MOD; the //printf ("fin\n"); the          for(intI=2; i*j<=who;i++) -         { the //printf ("!! %d%d\n ", i,i*j); theans[j]= (ans[j]-ans[i*j]+mod)%MOD; the         }94An= (an+ (LL) j*ans[j]%mod)%MOD; the //printf ("!! \ n "); the     } theprintf"%d\n", an);98     return 0; About}

(tolerance) Codeforces Round #428 (Div. 2) D. Winter is here

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.