Prime with 3 factors
You are given an array ‘ARR’ consisting of ‘N’ positive integers. Your task is to find if the number has exactly 3 factors for each number in the array ‘ARR’.
You have to return an array consisting of ‘0,’ and ‘1’ where ‘0’ means that ‘ARR[index]’ does not have 3 factors and ‘1’ means ‘ARR[index]’ has exactly 3 factors.
For Example:
If ‘N’ = 4 and ‘ARR’ = [3, 5, 4, 2].
3 has 2 factors, which are 1 and 3.
5 has 2 factors, which are 1 and 5.
4 has 3 factors, which are 1, 2 and 4.
2 has 2 factors, which are 1 and 2.
Hence, the answer is [0, 0, 1, 0].
Input format :
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case contains a single integer ‘N’ denoting the number of elements in the array.
The next line contains ‘N’ space-separated integers denoting the elements of array ‘ARR’.
Output format :
For each test case, print an array containing 0 and 1 where 1 is present if the number ‘ARR[index]’ has exactly 3 factors. Otherwise, 0 is present.
Print the output of each test case in a separate line.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints :
1 <= T <= 10
1 <= N <= 10^6
1 < ARR[index] <= 10^12
Time Limit: 1 second
CodingNinjas
author
2y
Step 1 : While n is divisible by 2, print 2 and divide n by 2.
Step 2 : After step 1, n must be odd. Now start a loop from i = 3 to square root of n. While i divides n, print i and divide n by i. After...read more
CodingNinjas
author
2y
Brute Force
In this approach, we will implement a function in which we have to pass an integer, and for each integer passed, the function returns the number of factors of that number. So we iterate ov...read more
CodingNinjas
author
2y
Sieve Of Eratosthenes
In this approach, we will make a sieve array that maintains whether that particular index is a prime number or not. If the index is a prime number, then the sieve[index] is equal...read more
Add answer anonymously...
Top Adobe Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app