EquateNumbers
Rookie SRM 12 · 2022-04-14 · by praveen123
Rookie SRM 12 · 2022-04-14 · by praveen123 · Simple Math
Problem Statement
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.
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
0)
{2, 4}
Returns: "yes"
You can replace 4 by its non trivial divisor 2 to make the elements of the array equal.
1)
{3, 6, 7}
Returns: "no"
You can not make all the elements by using the operation described in the statement. So, answer is "no".
2)
{516489004,351371688,811236122,359319772}
Returns: "yes"
3)
{774790715,541447280,142096365,445121785,583653195,71374815,798454490,409670625,942953335,8997395}
Returns: "yes"
4)
{1, 1, 1}
Returns: "yes"
The numbers are already equal.
Submissions are judged against all 154 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class EquateNumbers with a public method string canMakeEqual(vector<int> A) · 154 test cases · 2 s / 256 MB per case