CF468C Hack It! Construction

Portal


Not enough people think of brain structure

Consider for an interval \ ([l, r] \ ) how to adjust it so that the final result is exactly plus \ (1 \) .

Note that for a \ (<10 ^ {18} \) number \ (X \) , \ (F (X + 10 ^ {18}) = F (X) + 1'd \) , so if \ (rl = 10 ^ {18} --1 \) and \ (L <10 ^ {18} \) , then the interval \ ([l, r] \ ) becomes the interval \ ([l + 1, r + 1] \) after that, the answer is just to increase \ (1 \) .

And \ (A \ Leq 18 is 10 ^ {} \) , so we take the initial \ (L = 0, R & lt = 18 is 10 ^ {-1} \) , then continue to the interval \ ([l, r] \ ) becomes for the interval \ ([L +. 1, R & lt +. 1] \) , certainly can not exceed \ (10 ^ {18} \) found to meet the secondary \ (\ bmod \ a = 0 \) a \ (l, r \) , i.e. each time the \ ([l, r] \ ) becomes \ ([l + 1, r + 1] \) when \ (L <18 is 10 ^ {} \) , so this is certainly possible constructed program.

Finally, we need to do is to find \ (\ sum \ limits_ {i = 0} ^ {10 {18} -1 ^} f (i) \) values of.

\(\begin{align*} \sum\limits_{i=0}^{10^{18}-1} f(i) & = 45 \times 10^{17} + 10 \times \sum\limits_{i=0}^{10^{17}-1} f(i) \\ & = 45 \times 10^{17} + 450 \times 10^{16} + 100 \times \sum\limits_{i=0}^{10^{16}-1} f(i) \\ &= ... \\ &= 45 \times 18 \times 10^{17} \\ &= 8.1 \times 10^{19} \end{align*}\)

So we let \ (L = A - (8.1 \ Times. 19 10 ^ {} \ MOD A), 18 is L + 10 ^ {-1} \ = R & lt) , it is a combination method of solution.

Note that the above guarantee the \ (l \ neq 0 \)

Here are a Do not write code?

Guess you like

Origin www.cnblogs.com/Itst/p/11295346.html