×

# Help required in this question

 0 Hi i am stucked in this problem https://www.hackerrank.com/contests/h42-finals/challenges/mathematical-graph. 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 ? asked 26 Feb '17, 18:10 3★sandeep9 478●2●8●27 accept rate: 4% 1 Link not working dear, please re-check. (26 Feb '17, 18:15) 2 https://www.hackerrank.com/contests/h42-finals/challenges/mathematical-graph (26 Feb '17, 22:35) All because of that '.' at the end, which many failed to notice! (26 Feb '17, 22:54) Thanks Utkarsh & Banshal :) (01 Mar '17, 16:22) sandeep93★

 2 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. answered 27 Feb '17, 01:13 2.8k●1●4●18 accept rate: 16% 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 :) (01 Mar '17, 16:46) sandeep93★
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×301
×198

question asked: 26 Feb '17, 18:10

question was seen: 443 times

last updated: 01 Mar '17, 16:46