Alle Herausforderungen
Schwierig 0 gelöst 0% Erfolgsquote

Cut a Rectangle Into Squares

Find the fewest straight cuts needed to produce only squares.

On each move, choose one rectangle and cut all the way across it, parallel to a side, making two rectangles with positive integer side lengths. Continue until every piece is a square. Squares may have different sizes. Count cuts, not pieces.

Implement rectangle_cutting(height, width).

Input

height: The starting rectangle height.

width: The starting rectangle width.

Output

Return the minimum number of cuts.

Einschränkungen

1 ≤ height, width ≤ 500. Rotation does not change the answer.

Beispiele

Beispiel 1
Eingabe:
width = 3
height = 2

Erwartete Ausgabe:
expected = 2
Eingabe:
long long width = 3;
long long height = 2;

Erwartete Ausgabe:
long long expected = 2;
Eingabe:
long width = 3;
long height = 2;

Erwartete Ausgabe:
long expected = 2;

Erläuterung

Cut off a 2 × 2 square, leaving a 2 × 1 rectangle. One more cut splits the remainder into two unit squares.

Beispiel 2
Eingabe:
width = 4
height = 4

Erwartete Ausgabe:
expected = 0
Eingabe:
long long width = 4;
long long height = 4;

Erwartete Ausgabe:
long long expected = 0;
Eingabe:
long width = 4;
long height = 4;

Erwartete Ausgabe:
long expected = 0;

Erläuterung

The starting rectangle is already a square.

Referenzen

Diese Aufgabe wurde für CodeUtility angepasst. Beachte die oben genannten Vorgaben und Einschränkungen.

Von anderen lernen

Community-Lösungen

Noch keine veröffentlichten Lösungen. Löse die Aufgabe und teile als Erster eine Lösung.