CCC '04 J1 - Squares

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 256M

Problem type
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

Copy
9

Sample Output 1

Copy
The largest square has side length 3.

Sample Input 2

Copy
8

Sample Output 2

Copy
The largest square has side length 2.

Sample Input 3

Copy
7535

Sample Output 3

Copy
The largest square has side length 86.

Comments


  • 0
    DavidZ2648  commented 41 days ago edit 2

    does anyone know why my code isn't working?

    Copy
    A = int(input())
    B = A // 3
    C = str(B)
    
    print("The largest square has side length", C + ".")
    

    • 0
      jamesimbeaultcanada  commented 36 days ago

      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.