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.
First part is to find formula for number of cubes in given layer. Then we need to calculate min and max values for formula factors. Then we need to calculate posible range of sum of two factors and solve for integer solutions of quadratic equations in the equation: A = B(x+y) + xy where x+y has relatively small range of values. For N=1000000 my algorithm takes about 70 ms.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #126: Cuboid layers
You are viewing a single comment's thread. Return to all comments →
First part is to find formula for number of cubes in given layer. Then we need to calculate min and max values for formula factors. Then we need to calculate posible range of sum of two factors and solve for integer solutions of quadratic equations in the equation: A = B(x+y) + xy where x+y has relatively small range of values. For N=1000000 my algorithm takes about 70 ms.