Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Ninja Competition

Easy
0/40
profile
Contributed by
76 upvotes
Asked in companies
Hexaware TechnologiesBottomline Technologies

Problem statement

Our hero Ninja is organizing a coding competition where only two teams can participate simultaneously. To make the competition interesting and fair, both the teams should have an equal number of members. As an organizer, Ninja got the task of making the two teams.

There are some conditions for creating teams. For each competition, he will be given a number ‘N’, and for each divisor ‘D’ of ‘N’ ( including 1 and ‘N’ itself ), he will add a member:

1) to the first team if ‘D’ is even.

2) to the second team if ‘D’ is odd.

Since Ninja is very busy organizing the event, he wants you to help him with the task. Your task is to tell Ninja if he can create two teams with an equal number of members.

For Example:
For ‘N’ = 10,
The divisors are:
1, 2, 5, 10.
The first team will have two members corresponding to divisors 2 and 10.
The second team will have two members corresponding to divisors 1 and 5.
So, in this case, Ninja can make two teams.
Detailed explanation ( Input/output format, Notes, Images )
Constraints:
1 <= T <= 100
1 <= N <= 10^5

It is guaranteed that the sum of N over all test cases doesn’t exceed 10^5.

Time Limit: 1 sec
Sample Input 1:
2
7
14
Sample Output 1:
false
true
Explanation For Sample Output 1:
In test case 1:

N = 7, the divisors of 7 are 1,7.
The first team will have 0 members since there are no even divisors.
The second team will have 2 members corresponding to divisors 1 and 7.
Since the teams have a different number of members, the output will be false.

In test case 2:

N=14, the divisors of 14 are 1,2,7,14.
The first team will have 2 members corresponding to divisors 2 and 14.
The second team will have 2 members corresponding to divisors 1 and 7.
Since the teams have the same number of members, the output will be true.
Sample Input 2:
2
2
20
Sample Output 2:
true
false
Full screen
Console