Search Here

Tuesday, April 25, 2017

UVa - 13153 ( Number Of Connected Components ) [ Analysis + Solution ]

=>Try Yourself First. For help Scroll Down .

Problem Link:  https://uva.onlinejudge.org/external/131/13153.pdf


⇒ Problem Clearance: 

You will be given N numbers which is between 1 & 106 . And you can draw an edge between any two number if the Greatest Common Divisor ( GCD ) of those two number is greater than 1 . Hence you made some conntection ( probably none ) among the nodes. Now you're going to find number of component that are connected together. 

⇒ Required Knowledge

Sieve of Erathothense + Prime Factorization + Depth First Search / Disjoint Set Union .

😤 Wow!!! Got the idea how to solve ??? Then Code it.😤

😡 Not Yet !! Continue Reading . 😡

 How To Solve ??
 Wrong Answer ????
Just think a bit. Is there any implementation error you did? Try to give an input of N prime number and see whether the result is N or not ? I mean check the result of following case is 4 or Not ? 
4
2 3 5 7
Try several cases like this . If they are giving correct output then there may be some corner case you missed. Try to open the next spoiler hint for you.

 Spoiler :




If you did not any implementation mistake in your code then your should be solved by now. If you're failed to solve yet then you may see the Solution given below or you may read the whole post once again and then code it again.

Code:




=>Leave a comment for any kinds of Hugs and / or Bugs. Thank you .

2 comments:

  1. বাংলায় লিখাটা হলে বুঝতে সুবিধা হতো ।

    ReplyDelete
  2. 1 এর বেলায় কেন এই স্পেশাল কেস?? একটু হাতে কলমে বুঝিয়ে দিলে ভালো হতো।।

    ReplyDelete