Canadian Computing Competition: 2004 Stage 1, Junior #1
Gigi likes to play with squares. She has a collection of equal-sized square tiles. Gigi wants to arrange some or all of her tiles on a table to form a solid square. What is the side length of the largest possible square that Gigi can build?
For example, when Gigi has 9 tiles she can use them all to build a square whose side length is 3. But when she has only 8 tiles, the largest square that she can build has side length 2.
Write a program that inputs the number of tiles and then prints out the maximum side length. You may assume that the number of tiles is less than ten thousand.
Sample Input 1
9
Sample Output 1
The largest square has side length 3.
Sample Input 2
8
Sample Output 2
The largest square has side length 2.
Sample Input 3
7535
Sample Output 3
The largest square has side length 86.
Comments
this is the kind of thing that makes you scratch your head, but when you write it you realize how short it can be
does anyone know why my code isn't working?
Why are you doing //3? just do sqrt
Hello there! I'm James and I would like to attempt at helping you with this. The main issue here is logic (no offense). B = A//3 does not make much sense in calculating what you would need. Here's a hint - you are finding the largest square, in terms of numbers, possible and you are rather not supposed to be doing floor division. To help you understand what // means, here is a quick list of what it does (none of this below is needed in this question, just good to know in general). 10//3 = 3
15//4 = 3
16//4 = 4 (also equal to 16/4)
7//2 = 3
7.0//2 = 3.0 (float becomes float)
I hope this helps! Please let me know if it did. Thank you for reading.