The number of balls that can be stacked in a square based pyramid is obtained by the sum of the squares of the different lengths of the layers.
Given that the number of the balls to be stacked is 525, the number of layers and the size of the base is obtained as follows:
[tex]1^2+2^2+3^2+4^2+5^2+6^2+7^2+8^2+9^2+10^2+11^2 \\ \\ =1+4+9+16+25+36+49+64+81+100+121 \\ \\ =506[/tex]
Thus, an 11 by 11 sized square base with 11 layers will use up 506 cannonballs remaining 525 - 506 = 19 cannonballs