Help required in this question

Hi i am stucked in this problem Programming Problems and Competitions :: HackerRank. Can anyone suggest an approach… I tried to calculate all the divisors of each no upto 10^6,but that’s a bit slow. What can be a faster approach to solve this ?

Link not working brother

1 Like

See My Solution

Here i just used a concept of DP, In which firstly i sort all the array in ascending order. After that i visit all the numbers that can be divisible by that particular number.

But the question is asking about the isolated number so i used a flag variable to check is there number has been visited so far or not. If i don’t found any number that aren’t given in arr[] and aslo not a factor of my first number then it means that there exist no factor of that particular element.

I hope you will get my logic. Otherwise just debug my code to know how it is working.

If you have any doubt then feel free to comment there.

2 Likes

Link not working dear, please re-check.

1 Like
2 Likes

All because of that ‘.’ at the end, which many failed to notice!

Thanks Utkarsh & Banshal :slight_smile:

I got it :),This idea didn’t came to my mind as say if all the no’s are same say 2 & N = 10^5,then the algo will time out…But now on reading the problem statment carefully,i am banging my head :(…Thanks a lot again :slight_smile: