Copier Reduction

Interview

Time limit1sMemory limit128 MB

Summary
Given an image and paper size in millimeters, find the largest integer percentage scale (with optional 90-degree rotation) that still fits on the paper.
Level

Easy3 of 10

Topics
Math, Implementation, Brute force, Geometry
Solved
No attempts yet

Problem

You need to copy an A×BA \times B mm image onto a C×DC \times D mm sheet of paper, keeping the image as large as possible.

You may rotate the image by 90 degrees (landscape orientation). If it still does not fit, you may shrink it uniformly to an integer percentage of its original size.

For example, to copy a 560×400 mm image onto a 216×280 mm sheet, you can rotate it to landscape and reduce it to 50% of its original size, giving 200×280 mm, which fits without overlapping any edge.

Given the image and paper dimensions, determine the largest integer percentage of the original size at which the image still fits on the paper (after an optional 90° rotation).

Input

The input contains one or more test cases. Each test case is a single line with four positive integers AA, BB, CC, and DD separated by spaces, describing an A×BA \times B mm image and a C×DC \times D mm sheet of paper. Every value is less than 1000.

The input ends with a line containing four zeros, which must not be processed.

Output

For each test case, print the largest integer percentage pp (with 1≤p≤1001 \le p \le 100) such that the image, scaled to p%p\% of its original size and optionally rotated 90°, fits on the paper without overlapping any edge. If the image already fits at its original size, print 100%.

It is guaranteed that the answer is always an integer percentage between 1% and 100% inclusive. Print each answer on its own line, followed by a percent sign, exactly as shown in the examples.

Examples1

  1. Example 1

    Input
    560 400 218 280
    10 25 88 10
    8 13 5 1
    9 13 10 6
    199 333 40 2
    75 90 218 280
    999 99 1 10
    0 0 0 0
    
    Expected output
    50%
    100%
    12%
    66%
    1%
    100%
    1%