
The first line of input contains an integer 'T' representing the number of test cases.
The first line of each test case contains an integer ‘N’ representing the number of integers in the array, ‘ARR’.
The second line of each test case contains ‘N’ space-separated integers representing the elements of the ‘ARR’ array.
For each test case, return the sum of divisors of the integers in ‘ARR’ with exactly four divisors. In case there is no such integer with exactly four divisors, then return 0.
The output of each test case will be printed in a separate line.
1 <= T <= 5
1 <= N <= 2000
1 <= ARR[ i ] <= 10 ^ 5
Where ‘T’ is the number of test cases, ‘N’ is the number of integers in the array, ‘ARR’ and ‘ARR[ i ]’ is the ‘i’th element in the ‘ARR’ array.
Time limit: 1 second
You do not need to print anything, it has already been taken care of. Just implement the given function.
The idea is to use the brute force approach. We will find the divisors for every element in the ‘ARR’. If the count of divisors becomes greater than 4, we will move to the next element. And if after finding all the divisors of an element, the number of divisors is exactly 4 then we will sum the divisors.
Algorithm:
For any integer greater than 1, ‘NUM’, it is obvious that 1 and ‘NUM’ are the divisors of ‘NUM’. So we already have two divisors. Also, if ‘i’ is a divisor of ‘NUM’ then ‘NUM / i’ is also a divisor of ‘NUM’. It means we only have to find a divisor, ‘i’ in between 2 to SQRT(NUM), and thus we will have 1, ‘NUM’, ‘i’ and ‘NUM / i’ as four divisors.
Please note that if ‘NUM’ is a perfect square and ‘i’ is a divisor of ‘NUM’ then ‘i’ and ‘NUM / i’ will be the same integer. In that case, ‘NUM’ will have only three divisors.
Algorithm:
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers