PermutationAndMultiplication
SRM 772 · 2019-12-10 · by abdullahkool768
Problem Statement
You are given two
- Let A be the largest integer whose binary representation consists of exactly ones 1s and zeroes 0s.
- Let B be the smallest integer whose binary representation consists of exactly ones 1s and zeroes 0s.
- Let C = A*B.
Compute and return the number of 1s in the binary representation of C.
Notes
- The binary representations of A and B are not allowed to have leading zeroes.
Constraints
- ones will be between 1 and 200,000, inclusive
- zeroes will be between 0 and 200,000, inclusive
26 32 Returns: 52
35 5 Returns: 35
20 20 Returns: 40
5 8 Returns: 10
9 21 Returns: 18
2 2 Returns: 4
A = 12 (in decimal) = 1100 (in binary) B = 9 (in decimal) = 1001 (in binary) Thus, A*B = 108 (in decimal) = 1101100 (in binary). The number 1101100 contains four 1s, so the correct answer is 4.
1 2 Returns: 1
Here we have A = B = 4, and thus A*B = 16. (In binary, A = B = 100 and A*B = 10000.)
Submissions are judged against all 171 archived test cases, of which 7 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class PermutationAndMultiplication with a public method int multiplyAndCount(int ones, int zeroes) · 171 test cases · 2 s / 256 MB per case