Under construction

Still being built. Things may change

Picture Perfect

Interview

Time limit1sMemory limit128 MB

Summary
For each C, find the factor pair (W, H) with W*H = C closest to a square, and report the smallest perimeter along with W and H.
Level

Easy3 of 10

Topics
Math, Brute force, Number theory, Implementation
Solved
No attempts yet

Problem

Roy has a stack of student yearbook photos. He wants to lay them on a flat surface edge to edge to form a completely filled rectangle whose perimeter is as small as possible. Every photo must be fully visible, and each photo is a square measuring 1×11 \times 1 unit.

For example, 1212 photos can be arranged as follows, where each photo is drawn as an X:

XXXX
XXXX
XXXX

They could also be turned the other way:

XXX
XXX
XXX
XXX

Both arrangements are completely filled rectangles with the same perimeter, 1414 units.

For a given number of photos CC, find the filled rectangle formed by placing all CC photos edge to edge that has the smallest possible perimeter, and report both that perimeter and the rectangle's dimensions.

Input

The input contains several test cases. Each test case is a single positive integer CC (1≤C<65 0001 \le C < 65\,000), the number of photos to lay out. The input ends with a line containing 00, which must not be processed.

Output

For each value of CC, print one line in exactly this format:

Minimum perimeter is P with dimensions W x H

Here PP is the smallest possible perimeter, and WW and HH are the side lengths of the rectangle that achieves it, with W≤HW \le H.

Examples1

  1. Example 1

    Input
    100
    15
    195
    0
    
    Expected output
    Minimum perimeter is 40 with dimensions 10 x 10
    Minimum perimeter is 16 with dimensions 3 x 5
    Minimum perimeter is 56 with dimensions 13 x 15