[2023 OUCC Round 1] Hailstones
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
The hailstones sequence of numbers is generated by:
Start with a number.
- If the number is even, divide the number by 2 to generate the next number.
- If the number is odd, multiply the number by 3 and add 1 to generate the next number.
- Repeat until the number is 1.
For example: 5 → 16 → 8 → 4 → 2 → 1.
It is believed that all hailstone sequences end with 1, no matter what the starting number is. You are interested in the proportion of odd and even numbers in a hailstone sequence.
Task:
Write a program that takes, as input, the starting value of a hailstone sequence. Your program should then determine how many even numbers and how many odd numbers it contains.
Constraints:
[Note: you do not need to check constraints in your code for this competition - they are just for information about the range of test data values.]
- All inputs provided by the testing server will result in hailstone sequences that end in 1.
- The starting number will not be less than 1 or greater than 200.
Input format:
- An integer.
Output format:
- Line 1: The number (integer) of even numbers in the sequence.
- Line 2: The number (integer) of odd numbers in the sequence.
Example:
5
4
2