Give you a sequence that allows you to calculate the sum of the number of its elements for all gcd that do not have a sequence of 1 gcd*.
SUM (i) is the number of multiples of I, which can be calculated by the allowance.
Look at this: http://blog.csdn.net/jaihk662/article/details/77161436.
Note 1*c (n,1) +2*c (n,2) +...+n*c (n,n) =n*2^ (n-1).
#include <cstdio>using namespace Std;typedef long ll; #define MOD 1000000007llint N;int a[200005],cnt[1000005] ; ll Sum[1000005],ans,pw[1000005];int Main () {pw[0]=1;for (int i=1;i<=1000000;++i) {pw[i]= (PW[I-1]*2LL)%MOD;} scanf ("%d", &n), for (int i=1;i<=n;++i) {scanf ("%d", &a[i]); ++cnt[a[i]];} for (int i=1000000;i>=2;--i) {int all=cnt[i];for (int j=i*2;j<=1000000;j+=i) {sum[i]= (sum[i]+mod-sum[j])%MOD; ALL+=CNT[J];} Sum[i]= (sum[i]+ (LL) all*pw[all-1])%mod)%mod;ans= (ans+ (LL) i*sum[i])%mod;} printf ("%i64d\n", ans); return 0;}
"Tolerance principle" codeforces Round #428 (Div. 2) D. Winter is here