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.
The first value of the list should be one number X such that :
A = gcd(X,??) In other words: X should be multiple of A.
Because the sum have to be minimal, lets try the lowest multiple of A (X = A).
From here, whats the second number Y of the list?
We have two restrictions of Y:
A = gcd(X,Y)
B = gcd(Y, ??)
In other words Y should be a multiple of A and a multiple of B.
Again, because the sum have to be minimal, get the lowest multiple of A and B ( Least Common Multiple)
Iterate from there...
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
John and GCD list
You are viewing a single comment's thread. Return to all comments →
Some hint:
Suppose the input is [A,B,C,,...]
The first value of the list should be one number X such that : A = gcd(X,??) In other words: X should be multiple of A.
Because the sum have to be minimal, lets try the lowest multiple of A (X = A).
From here, whats the second number Y of the list? We have two restrictions of Y: A = gcd(X,Y) B = gcd(Y, ??) In other words Y should be a multiple of A and a multiple of B. Again, because the sum have to be minimal, get the lowest multiple of A and B ( Least Common Multiple)
Iterate from there...