[문제요약] 네자리수 이하의 자연수를 입력받아, 세번째 자릿수와 두번째 자릿수를 합쳐서 두 자리수 이하의 수를 만드는 과정 k를 수행한다. 같은 수가 나오지 않을 때까지 과정 k를 수행한 횟수를 출력한다.
Num Middle Square 7339 33 1089 1089 8 64 64 6 36 36 3 9 9 0 0 0 0 0The 'pigeon hole principle' tells us that the random numbers surely must repeat after no more than 10,000 of them -- and the sequence above repeats after just six numbers (the next number and all subsequent numbers are 0).
Note that some sequences repeat in a more complex way; this one alternates back and forth between 576 and 3249:
Num Middle Square 2245 24 576 576 57 3249 3249 24 576Your job is to tell Bessie the count of 'random numbers' that can be generated from a starting number before the sequence repeats a previously seen number. In the first case above, the answer is '6'. In the 'alternating' case, the answer is '3'.
입력 7339 출력 6
출처:usaco 2010 DEC bronze 요약: pl0892029