कठिन 0 हल किए गए 0% स्वीकृति

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.

सीमाएँ

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

उदाहरण

उदाहरण 1
इनपुट:
width = 3
height = 2

अपेक्षित आउटपुट:
expected = 2
इनपुट:
long long width = 3;
long long height = 2;

अपेक्षित आउटपुट:
long long expected = 2;
इनपुट:
long width = 3;
long height = 2;

अपेक्षित आउटपुट:
long expected = 2;

व्याख्या

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

उदाहरण 2
इनपुट:
width = 4
height = 4

अपेक्षित आउटपुट:
expected = 0
इनपुट:
long long width = 4;
long long height = 4;

अपेक्षित आउटपुट:
long long expected = 0;
इनपुट:
long width = 4;
long height = 4;

अपेक्षित आउटपुट:
long expected = 0;

व्याख्या

The starting rectangle is already a square.

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।