Project Euler — Problem 85


By count­ing care­ful­ly it can be seen that a rec­tan­gu­lar grid mea­sur­ing 3 by 2 con­tains eigh­teen rec­tan­gles:


Although there exists no rec­tan­gu­lar grid that con­tains exact­ly two mil­lion rec­tan­gles, find the area of the grid with the near­est solu­tion.


This prob­lem looks more dif­fi­cult than it is, I’m not going to go into the details here but basi­cal­ly the num­ber of rec­tan­gles inside a x by y grid can be cal­cu­lat­ed as:


The rest is fair­ly easy, just pick a range of x and y val­ues you want to try and brute force it!