Connection Status:
Competition Arena > TaroJiroDividing
SRM 650 · 2015-01-29 · by Witaliy · Brute Force
Class Name: TaroJiroDividing
Return Type: int
Method Name: getNumber
Arg Types: (int, int)
Problem Statement

Problem Statement

The dividing game is played as follows: You start by taking a clean sheet of paper and writing down some positive integer. Then you repeat the following process: Let X be the last integer you wrote. If X is odd, the game ends. Otherwise, divide X by 2 and write down the result.

For example, if you start the game by writing 12 you will then write 12/2 = 6, followed by 6/2 = 3, and as 3 is odd, the game ends there. Your paper now contains the numbers 12, 6, and 3.

Cat Taro has just played the game starting with the integer A. Jiro has also played the game but he started with the integer B. You are given the ints A and B. Return the number of integers that were written both by Taro and by Jiro.

Constraints

  • A and B will be between 1 and 1,000,000,000, inclusive.
Examples
0)
8
4
Returns: 3

Taro will write the integers {8,4,2,1}. Jiro will write {4,2,1}. The three integers written by both of them are 4, 2, and 1.

1)
4
7
Returns: 0
2)
12
12
Returns: 3
3)
24
96
Returns: 4
4)
1000000000
999999999
Returns: 0

Submissions are judged against all 118 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class TaroJiroDividing with a public method int getNumber(int A, int B) · 118 test cases · 2 s / 256 MB per case

Submitting as anonymous