TCO Round 2A DIV1

Source: Internet
Author: User

Modmodmod Idiot number theory test instructions:

This is a problem to sell. Give you a modulo sequence $m$, make $f (x) = (\cdots (x\ mod\ m[0]) \ MoD m[1]) \mod m[2]\cdots $, ask you what the value of $\sum_{i=1}^r F (i) $ is

Exercises

Easy to know a little, if $i<j$ and $m[i]\le m[j]$, then $m[j]$ is meaningless, so first will m into a descending sequence. The next step is to observe the result after each modulo, since it is from 1 to r, so the sequence will become after the first modulo:

$$ (0+1+2+\cdots+m[0]-1) + (0+1+2+\cdots+m[0]-1) +\cdots+ (0+1+2+\cdots+m[0]-1) + (0+1+2+\cdots+r\ mod\ m[0]) $$

of which $0+1+2+\cdots+m[0]-1$ altogether have $r/m[0]$, because $f (0) =0$, so it becomes the same as the original problem of sub-problem, recursive solution can be.

Code:
#include <iostream>#include<cstring>#include<vector>#include<algorithm>using namespaceStd;vector<int>v;Long LongDfsintIintx) {if(x = =0)return 0; if(i = = V.size ())return(1+ x) * X/2; returnX/v[i] * DFS (i +1, V[i]-1) + DFS (i +1, X%v[i]);}classmodmodmod{ Public:    Long LongFindsum (Vector <int> m,intR) {V.push_back (m[0]);  for(intI=1; I<m.size (); i++)            if(V[v.size ()-1]>M[i]) v.push_back (M[i]); returnDfs0, R); }};
View Code

TCO Round 2A DIV1

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.