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