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

5679번 - Hailstone Sequences 다국어

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

문제

Consider the sequence formed by starting from a positive integer h0 and iterating with n = 1, 2, ... the following definition until hn = 1:

  • hn = hn-1 / 2 (if hn-1 is even)
  • hn = 3 × hn-1 + 1 (if hn-1 is odd)

For instance, if we start with h0 = 5 the following sequence is generated: 5, 16, 8, 4, 2, 1. If we start with h0 = 11, the sequence generated is 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1.

As you can see from these examples, the numbers go up and down, but eventually comes down to end in 1 (at least for all numbers that have ever been tried). These sequences are called Hailstone sequences because they are similar to the formation of hailstones, which get carried upward by the winds over and over again before they finally descend to the ground.

In this problem, given a positive integer, your task is to compute the highest number in the Hailstone sequence which starts with the given number.

입력

Each test case is described using a single line. The line contains an integer H representing the starting value to build the sequence (1 ≤ H ≤ 500).

The last test case is followed by a line containing one zero.

출력

For each test case output a line with an integer representing the highest number in the Hailstone sequence that starts with the given input value.

제한

예제 입력 1

5
11
27
0

예제 출력 1

16
52
9232

힌트

출처

ICPC > Regionals > Latin America > Latin America Regional Contests > Latin America Regional Contests 2011 연습 세션 PB번

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

출처

대학교 대회

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

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