Problem Statement
Given an array A consisting of n integers. You have to tell whether you can make all of them equal by applying following operation as many times as you want.
- Choose any number in the array and replace it by any non trivial divisor of it.
Return "yes" or "no" according to the situation.
Definition
- Class:
- EquateNumbers
- Method:
- canMakeEqual
- Parameters:
- int[]
- Returns:
- String
- Method signature:
- String canMakeEqual(int[] A)
- (be sure your method is public)
Notes
- A non-trivial divisor of n is any positive integer other than 1 or n.
Constraints
- n will be between 1 and 50, inclusive.
- Each element of A will be between 1 and 109, inclusive.
Examples
{2, 4}Returns: "yes"
You can replace 4 by its non trivial divisor 2 to make the elements of the array equal.{3, 6, 7}Returns: "no"
You can not make all the elements by using the operation described in the statement. So, answer is "no".{516489004,351371688,811236122,359319772}Returns: "yes"
{774790715,541447280,142096365,445121785,583653195,71374815,798454490,409670625,942953335,8997395}Returns: "yes"
{1, 1, 1}Returns: "yes"
The numbers are already equal.