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

13236번 - Collatz Conjecture 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB1353103694277.787%

문제

The Collatz conjecture is a conjecture in mathematics named after Lothar Collatz, who first proposed it in 1937 and is still an open problem in mathematics. The sequence of numbers involved is referred to as the hailstone sequence or hailstone numbers (because the values are usually subject to multiple descents and ascents like hailstones in a cloud. The conjecture is that no matter what number you start with, you will always eventually reach 1. The property has also been called oneness.

The computation (also known as 3n + 1) is stated as follows:

  1. We have an integer number n.
  2. If n == 1: stop
  3. If n is even: divide the number by 2. Then go to step 1
  4. If n is odd: multiply by 3 and add 1. Then go to step 1

As the conjecture states, you repeat this steps for any positive integer you will eventually end up with n = 1. The values we find define a sequence from n to 1.

For example, if we start with n = 14.

  • 14 is even so the new value will be 7 (14/2)
  • 7 is odd so the new value will be 22 (3*7 + 1)
  • 22 is even so the new value will be 11 (22/2)
  • 11 is odd so the new value will be 34 (3*11 + 1)
  • 34 is even so the new value will be 17

If we continue until we have a value of 1, the final sequence will be:

14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1

Your task is to write a program that, given the starting point n, prints the whole Collatz sequence for this value.

입력

A integer value n. The value of n will be between 1 and 100000.

출력

Print the Collatz sequence with the elements separated by a single space. Do not add any space at the beginning or the end of the line.

제한

예제 입력 1

14

예제 출력 1

14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

예제 입력 2

1

예제 출력 2

1

예제 입력 3

64

예제 출력 3

64 32 16 8 4 2 1

힌트

출처

Olympiad > All-Ireland Programming Olympiad > 2016 AIPO Preliminary Round 3번

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

출처

대학교 대회

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

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