TopcoderArchiveVisit Topcoder
SRM27 Nov 2017
SRM 724

OrAndSumEasy

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given two non-negative integers: the longs pairOr and pairSum.

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.

Definition

Class:
OrAndSumEasy
Method:
isPossible
Parameters:
long, long
Returns:
String
Method signature:
String isPossible(long pairOr, long pairSum)
(be sure your method is public)

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

  1. 7
    11
    Returns: "Possible"
    One of the solution is: A = 5 and B = 6.
  2. 11
    7
    Returns: "Impossible"
    We can show the sum should be at least as large as or, so it is impossible.
  3. 999799115789631487
    999999999999999999
    Returns: "Possible"
    One of the solution is a = 111111111111111111, b = 888888888888888888.
  4. 1
    100
    Returns: "Impossible"
  5. 0
    0
    Returns: "Possible"
Back to all problems