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.
Clearly, the largest decent number will have all the 5's first, and all the threes last, so we really just need to compute the number of 3's and 5's in the largest number.
You can do this by writing up the problem as a system of linear diophantine equations. if x is the number of 5s, and y is the number of 3s, we have the following constraints:
x + y == n
x % 3 == 0
y % 5 == 0
which can be rewritten as:
x % 3 == 0
x % 5 == n % 5
one solution to this is to plug in x = 6n as a solution. If you have one solution, all other solutions are related to the one you have by multiples of 15 (try proving this yourself by looking at the difference between two solutions). So I pick the solution with the largest number of 5s.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sherlock and The Beast
You are viewing a single comment's thread. Return to all comments →
Clearly, the largest decent number will have all the 5's first, and all the threes last, so we really just need to compute the number of 3's and 5's in the largest number.
You can do this by writing up the problem as a system of linear diophantine equations. if x is the number of 5s, and y is the number of 3s, we have the following constraints:
which can be rewritten as:
one solution to this is to plug in x = 6n as a solution. If you have one solution, all other solutions are related to the one you have by multiples of 15 (try proving this yourself by looking at the difference between two solutions). So I pick the solution with the largest number of 5s.