OrAndSumEasy
SRM 724 · 2017-11-27 · by cgy4ever
SRM 724 · 2017-11-27 · by cgy4ever · Math
Problem Statement
Problem Statement
You are given two non-negative integers: the long s pairOr and pairSum.
Determine whether it is possible that for two non-negative integers A and B we have both:
Above, "or" denotes the bitwise-or operator. Each bit of the result is the logical or of the corresponding bits of the operands. For example, in base 2 we have (1100 or 0101) = 1101. The same equation with the numbers written in base 10 looks as follows: (12 or 5) = 13.
Return "Possible" if we can find such A and B, and "Impossible" if not.
Determine whether it is possible that for two non-negative integers A and B we have both:
- A or B = pairOr
- A + B = pairSum
Above, "or" denotes the bitwise-or operator. Each bit of the result is the logical or of the corresponding bits of the operands. For example, in base 2 we have (1100 or 0101) = 1101. The same equation with the numbers written in base 10 looks as follows: (12 or 5) = 13.
Return "Possible" if we can find such A and B, and "Impossible" if not.
Constraints
- pairOr will be between 0 and 1,000,000,000,000,000,000 (10^18), inclusive.
- pairSum will be between 0 and 1,000,000,000,000,000,000 (10^18), inclusive.
Examples
0)
7 11 Returns: "Possible"
One of the solution is: A = 5 and B = 6.
1)
11 7 Returns: "Impossible"
We can show the sum should be at least as large as or, so it is impossible.
2)
999799115789631487 999999999999999999 Returns: "Possible"
One of the solution is a = 111111111111111111, b = 888888888888888888.
3)
1 100 Returns: "Impossible"
4)
0 0 Returns: "Possible"
Submissions are judged against all 136 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class OrAndSumEasy with a public method string isPossible(long long pairOr, long long pairSum) · 136 test cases · 2 s / 256 MB per case