Reputation: 15
The question is what is the smallest possible value of N so R= 41441? I did the problem and the result is 1234 but I am curious if there is an easier and faster way to do such problems. What I did is simulate the algorithm running in my head from the end to beginning until I get the first number which is also the answer. TBD the last number that gets run in the flow is 1 because 1 div 5 is 0 and 1 mod 5 is 1 which is the final number of R, then the number before that that was ran was 9 because 9 mod 5 is 4 which is the second last number of R and 9 div 5 is 1 which is the next number that runs in the flow. I kept on doing that until I made it to the final number which is 1234 and gives me all the numbers I need for R: 41441.
Are there any clever methods for doing these problems in a more efficient way?
Upvotes: 0
Views: 254
Reputation: 2129
The problem of finding N
is equivalent to the problem of finding the conversion to base 10 of the number in base 5 "14414"
which is the string R
reversed. This just follows from what a base b representation is, and what the fact that if you have a number N in base b, N mod b
just gives you the last digit, and N div b
gives you the number with the last digit chopped of.
Upvotes: 1