Logo
(追記) (追記ここまで)

5948번 - Bad Random Numbers 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB53842738979.388%

문제

Bessie is trying to generate random numbers. She stumbled upon an old reference to the 'middle square' method for making numbers that appear to be random. It works like this:

  • Pick a starting four digit number (1 <= N <= 9999)
  • Extract its middle two digits (the hundreds and tens digit) as a number
  • Compute the square of those two digits
  • That square is the 'random number' and becomes the new starting number

Here's a sample:

 Num Middle Square
 7339 33 1089
 1089 8 64
 64 6 36
 36 3 9
 9 0 0
 0 0 0

The '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 576 

Your 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'.

입력

  • Line 1: A single integer: N

출력

  • Line 1: A single integer that is the count of iterations through the middle square random number generator before a previous value is repeated

제한

예제 입력 1

7339

예제 출력 1

6

힌트

출처

Olympiad > USA Computing Olympiad > 2010-2011 Season > USACO December 2010 Contest > Bronze 2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /