Jaehong's Ladder
InterviewTime limit2sMemory limit512 MB
Given a rectangle's width, height, and a number of vertical strips, sum the lengths of the N-1 rungs where the strips cross the rectangle's diagonals.
- Level
Medium4 of 10
- Topics
- Math, Geometry, Implementation, Prefix sum
- Solved
- No attempts yet
Problem
Jaehong loves going up to the roof of his house. Last night's storm broke every ladder that led up there. He will use the two long logs he already owns as the side rails, buy wood only for the rungs, and build two ladders, the one he installs and a spare.
His design is this. He crosses the two logs of equal length at their midpoints so that the four endpoints form a rectangle of width and height . The two logs are then the diagonals of that rectangle. He cuts the rectangle into equal parts with vertical lines, and on each line the segment joining the two points where the line meets the logs becomes one rung. If the two points are at the same position, that rung has length 0. The rungs at the two ends rest on the ground, so he does not buy them, and only the inner lines count. Compute the total length of wood Jaehong has to buy for the rungs.
Input
The first line contains the width (), the height (), and the number of parts (), in this order. All three values are natural numbers.
Output
Print the total length of wood needed for the rungs on one line, rounded to six digits after the decimal point. Ignore the girth and thickness of the logs and of the wood. No piece of wood is rotten or cut away, so every piece is whole.
Hint

The sum of all the lengths is .