TopcoderArchiveVisit Topcoder
SRM25 Jun 2013
SRM 597

LittleElephantAndDouble

Problem statement, definition, constraints, and public examples.

Problem Statement

Little Elephant from the Zoo of Lviv likes integers.

You are given an int[] A. On a single turn, Little Elephant can double (i.e., multiply by 2) any element of A. He may double the same element more than once, if he wants to. He wants to obtain an array in which all elements are equal. Return "YES" (quotes for clarity) if it is possible to do that and "NO" otherwise.

Definition

Class:
LittleElephantAndDouble
Method:
getAnswer
Parameters:
int[]
Returns:
String
Method signature:
String getAnswer(int[] A)
(be sure your method is public)

Notes

  • The return value is case-sensitive. Make sure that you return the exact strings "YES" and "NO".

Constraints

  • A will contain between 1 and 50 elements, inclusive.
  • Each element of A will be between 1 and 1,000,000,000, inclusive.

Examples

  1. {1, 2}
    Returns: "YES"
    One possible way of making all elements equal is to double the element at index 0.
  2. {1, 2, 3}
    Returns: "NO"
    It's impossible to make all three elements equal in this case.
  3. {4, 8, 2, 1, 16}
    Returns: "YES"
  4. {94, 752, 94, 376, 1504}
    Returns: "YES"
  5. {148, 298, 1184}
    Returns: "NO"
  6. {7, 7, 7, 7}
    Returns: "YES"
Back to all problems