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
kobortor used the Quake III fast inverse square root algorithm (comments are still the same in the code, check submissions for C, he is 2nd place). Wikipedia Article, Submission
I don't understand why my code is not accepted. Its works in PyCharm, but not here (?) Please HELP ! ;)
Thanks !
Don't post code in the comments, anyone who has solved the problem can see your submissions.
It is not sufficient to print only the number, you have to print the whole sentence.
ok, thank you for the tip. Sorry, this is my first experiments here :)
Similar Dynamic programming.
uhhhh guys when i do my code, how do i cancel the space before the period??
i spent half an hour big-braining some loop logic and then found out I could have just rounded down with int lol
My math is really bad, like i got a C+ for my grade, and i dont really know what the pattern is, could someone help me?
you really should practice math-get a Complete Mathsmart book
try thinking about what square rooting a number does
The area formula for a square of side length
s
iss
^2 (s
squared, ors*s
). This problem is asking you, given a maximal value for the total area of the square, what is the maximal Integer side length that would fit? Integer means that there are no decimal side lengths in the square.In the example, if you had 8 blocks, only the side lengths
1
and2
would fit (1*1 < 8
, and2*2 < 8
). Of these, the two numbers, the maximum is 2 (because2>1
). Additionally, it can't be3
, or anything larger, because3*3 = 9
, and9 > 8
.very good calculation
How do I do this? A simple nudge towards the right side would be nice.
Thank you.
think about using sqrt
Ohhhhh... Thank you so much! You are so smart! Of course... square roots will be used! I am literally so dumb! Thank you once again!
I didn't know what was wrong with my code for a long time, then I realized I forgot a period.
That got me too. Don't forget the period after the side length of the square.
This comment is hidden due to too much negative feedback. Show it anyway.
You are not receiving TLE but WA, meaning your program produced the wrong answer in 0.1 seconds. The output we show you is not the full output; the (clipped) means we only show a certain prefix of your output. For most problems this is the first 32 bytes.
Yay FatalEagle! my fav