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.
After figuring out (which is the most difficult part IMHO) the maximum remainder for a particular and , taking special care of , , we can obtain an solution making use of the formula of sum of cubes , sum of squares and sum of consecutive integers .
I was unable to formally express how the maximum remainder can be found, and I suppose it would somehow begin with if is even and if is odd, and that any terms having as its factor could be ignored (therefore only look at the last or the last two terms depending on ), so we can pick that is best for what we want. The way I did it was to brute force some input and guess the pattern, though.
I believe you should be looking at:
odd : when , and
even : when .
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #120: Square remainders
You are viewing a single comment's thread. Return to all comments →
After figuring out (which is the most difficult part IMHO) the maximum remainder for a particular and , taking special care of , , we can obtain an solution making use of the formula of sum of cubes , sum of squares and sum of consecutive integers .
I was unable to formally express how the maximum remainder can be found, and I suppose it would somehow begin with if is even and if is odd, and that any terms having as its factor could be ignored (therefore only look at the last or the last two terms depending on ), so we can pick that is best for what we want. The way I did it was to brute force some input and guess the pattern, though.
I believe you should be looking at: