The problem
Bessie is excited about number theory: the study of integers (and things that behave like them). Today she is experimenting with a famous problem about integers.
She starts with a number N (2 \leq N \leq 10^5), and then repeats the following:
- If Bessie’s current number is even, she divides it by 2.
- Otherwise, she multiplies it by 3 and adds 1 .
Once Bessie reaches the number $1 ,$she stops.
For example, suppose Bessie started with $N = 3.$Then she would proceed through: 3 \to 10 \to 5 \to 16 \to 8 \to 4 \to 2 \to 1.
Given $N,$determine how many different numbers Bessie will encounter in total, including her initial $N$and 1 .
It is guaranteed, in this problem, that Bessie…
- will always eventually reach 1
- will never repeat a number
- will never see a number larger than 10^9
SAMPLE INPUT(N)
3
SAMPLE OUTPUT
8
I don’t know why im getting 2 different numbers as a output.
This is my code.
code
N = int(input())
total_numbers = 1
while N != 1:
if N % 2 == 0:
N = N / 2
total_numbers += 1
else:
N= N * 3 + 1
total_numbers += 1
print(total_numbers)