Connection Status:
Competition Arena > PermutationAndMultiplication
SRM 772 · 2019-12-10 · by abdullahkool768 · Simulation, String Manipulation
Class Name: PermutationAndMultiplication
Return Type: int
Method Name: multiplyAndCount
Arg Types: (int, int)
Problem Statement

Problem Statement

You are given two ints: ones and zeroes. You need to do the following:

  1. Let A be the largest integer whose binary representation consists of exactly ones 1s and zeroes 0s.
  2. Let B be the smallest integer whose binary representation consists of exactly ones 1s and zeroes 0s.
  3. 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
Examples
0)
26
32
Returns: 52
1)
35
5
Returns: 35
2)
20
20
Returns: 40
3)
5
8
Returns: 10
4)
9
21
Returns: 18
150)
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.

151)
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.

Coding Area

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

Submitting as anonymous