CF839D Winter is here
#include<bits/stdc++.h> #define r register using namespace std; const int N=1e6+5,Mod=1e9+7; int n,fac[N],cnt[N],dp[N],cur,ans; int main() { scanf("%d",&n); fac[0]=1; for (r int i=1;i<=n;i++) fac[i]=2ll*fac[i-1]%Mod; for (r int i=1,x;i<=n;i++) scanf("%d",&x),cnt[x]++; for (r int i=N-1;i>1;i--) { cur=0; for (r int j=i;j<N;j+=i) cur+=cnt[j]; if (!cur) continue; dp[i]=1ll*fac[cur-1]*cur%Mod; for (r int j=i+i;j<N;j+=i) dp[i]=(dp[i]-dp[j]+Mod) % Mod; ans=(ans+1ll*dp[i]*i%Mod)%Mod; } printf("%d\n",ans); return 0; }
愿你走出半生,归来仍是少年