参考http://m.blog.csdn.net/Hallelujah520/article/details/77164467
和http://m.blog.csdn.net/Hallelujah520/article/details/77164467
要容斥是因为这个地方算的是组合数的公式,所以有些地方的gcd是4,不是2的情况
差的地方:
1:这个地方的公式不会推。。
2:对于这个地方的容斥,想不到还能这样处理,而且这个复杂度不会爆。。。
不敲了,直接复制别人的代码。。
#include<stdio.h>
#define mod 1000000007
#define LL long long
LL cnt[1000005], sum[1000005];
LL Pow(LL a, LL b)
{
LL now;
now = 1;
while(b)
{
if(b%2)
now = now*a%mod;
a = a*a%mod;
b /= 2;
}
return now;
}
int main(void)
{
LL ans, i, j, n, x;
scanf("%lld", &n);
for(i=1;i<=n;i++)
{
scanf("%lld", &x);
cnt[x]++;
}
ans = 0;
for(i=1000000;i>=2;i--)
{
x = 0;
for(j=i;j<=1000000;j+=i)
{
sum[i] -= sum[j];
x += cnt[j];
}
sum[i] += x*Pow(2, x-1)%mod;
ans = ((ans+sum[i]*i)%mod+mod)%mod;
}
printf("%lld\n", ans);
return 0;
}