We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Dynamic Programming
  4. GCD Matrix
  5. Discussions

GCD Matrix

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 12 Discussions, By:

votes

Please Login in order to post a comment

  • chris_neuman1
    5 years ago+ 1 comment

    So, I've been staring at this problem for about an hour now. Trying to break it down into steps.

    I get what it's doing, taking the input, building out the 2 arrays that's essentially creating the matrix.

    Then, putting values into those array slots with a for loop using the iterator (a_i and b_i) to move through the array, but not create an array longer than whats needed.

    Then, taking the input for r1, c1, r2, c2 to specify a submatrix.

    I also found information on how to calculate GCD in Java using Euclid’s method seen here: http://www.java67.com/2012/08/java-program-to-find-gcd-of-two-numbers.html

    What I haven't been able to figure out, is how to get get Java to look at each position within the submatrix (after calculating GCD) and count how many unique numbers exist within.

    I started the 30 days of code to get some practice with Java, I'm self-taught so far and have never programmed professionally. How do you go from a "Hello World" program in my 1st challenge, to this in the 2nd challenge?

    Can anyone shed some light on this or maybe direct me to a more beginner friendly challenge series?

    2|
    Permalink
  • julie_larson
    5 years ago+ 2 comments

    Can anyone provide working more working test cases?

    1|
    Permalink
  • rentziass
    5 years ago+ 0 comments

    Can't get to the second half of test cases, apparently storing gcd results is not enough :D

    1|
    Permalink
  • thanhdatuetk62
    2 years ago+ 0 comments

    If you know about Mobius function and Inclusive-Exclusive Principle, solving this problem is more comfortable !

    0|
    Permalink
  • gslohith5
    3 years ago+ 0 comments

    You can refer following resource for more on GCD.

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature