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

Source: Internet
Author: User
Tags gcd

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

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.