LearnPy Hub
← Iterators & Generators problems
Hard

Collatz Generator

Write a generator collatz(n) yielding n and then every next value (n/2 if even, 3n+1 if odd) until it yields 1. Read n and print the sequence length and its largest value without building a list.

Input

One integer n ≥ 1.

Output

Two lines.

Sample 1

Input
6
Output
9
16

Sample 2

Input
1
Output
1
1
solution.py
Output appears here
Collatz Generator · Python practice problem · LearnPy Hub