#TCTM15124. Squares
Squares
Squares
题目描述
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?Gigi 喜欢玩方块。她收藏了一堆大小相等的方形瓷砖。Gigi 想把她的部分或全部瓷砖放在桌子上,形成一个实心的正方形。Gigi可以建造的最大正方形的边长是多少?
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.
例如,当Gigi有9块瓷砖时,她可以用它们来构建一个边长为3的正方形。但当她只有8块瓷砖时,她能建造的最大的正方形边长为2。
Write a program that asks the userfor the number of tiles and then prints out the maximum side length. You may assume that the user will only type integers that are less than ten thousand. Once your program has read the user’s input and printed the largest square, your program stops executing.
编写一个程序,询问用户瓷砖的数量,然后输出可以构成的最大正方形的边长。你可以假设用户只会输入小于一万的整数。一旦你的程序读取了用户的输入并打印出了最大的正方形边长,程序就停止执行。
There are many different methods that your program might use to find the answer. You may use any method. For example, here is one method. First, check whether there are enough tiles to build a square of side length 1. If there are enough tiles, then move on to check the side lengths 2, 3, 4, etc., until your program finds a length that is too large.
你的程序可以使用许多不同的方法来找到答案。你可以使用任何方法。例如,这里有一种方法。首先,检查是否有足够的瓷砖来构建一个边长为1的正方形。如果有足够的瓷砖,那么继续检查边长为2、3、4等的正方形,直到你的程序找到一个边长过大的情况。
输入格式
输入正方形瓷砖的数量。输出格式
输出构建的最大正方形边长。9
The largest square has side length 3.
8
The largest square has side length 2.
7535
The largest square has side length 86.