Link:
Http://codeforces.com/contest/839/problem/D
Test instructions
Give some number, ask to take out some number, when their gcd is greater than 0 o'clock, multiply the number by GCD to the answer, seek to accumulate and.
Exercises
When the game was over, I forgot to think about it, and when WA fell, it was possible to repeat it, but I couldn't write it.
This problem needs to know that a formula is 1*c (n,1) +2*c (n,2) +3*c (n,3) +...+n*c (n,n) = n*2^ (n-1)
We enumerate GCD, counting the number of numbers for its multiples, first assuming that it can make up the number of sets of contributions,
But we find that there are redundant statistics in the process of statistics, such as 4 and 8 are multiples of 2,
However, their gcd equals 4, so our contribution to each set number is subtracted from the number of aggregates of all its multiples,
Just pour the allowance.
Code:
to intN; + intA[MAXN], DP[MAXN], PW[MAXN], MX; - the intMain () { *Ios::sync_with_stdio (false), Cin.tie (0); $pw[0] =1;Panax NotoginsengRep (I,1, MAXN) Pw[i] =2* Pw[i-1] %MOD; -CIN >>N; theRep (I,0, N) { + intx; ACIN >>x; thea[x]++; +MX =max (MX, x); - } $ intAns =0; $ for(inti = mx; i >1; i--) { - intt =0; - for(intj = i; J <= MX; J + = i) T + =A[j]; the if(!t)Continue; -Dp[i] = 1LL * T*pw[t-1] %MOD;Wuyi for(intj =2I J <= MX; J + =i) theDp[i] = (Dp[i]-dp[j] + MOD)%MOD; -Ans = (ans + 1LL * dp[i] * i)%MOD; Wu } -cout << ans <<Endl; About return 0; $}
Codeforces Round #428 (Div. 2) D. Winter is here Math