Keyword: simulation, precalculation.

Algorithm:

First, calculate the next element in the sequence each of the 3000 numbers.

Then count how many elements are there in the sequence of each number.

Finally, scan through the specified range to get the answer.

Note: Be aware of those whose next element is equal to itself.

Code:

 

arrow
arrow
    全站熱搜

    dibery 發表在 痞客邦 留言(0) 人氣()