X DAYS

:

HOUR

:

MINS

:

SEC

Copied to Clipboard
Squares in Rectangle
Easy Accuracy: 48.39% Submissions: 277 Points: 2

Given a rectangle of size L x B. Find the minimum number of squares required to fill the rectangle such that no two square overlaps.

Example 1:

Input: L = 4, B = 5
Output: 5
Explaination: One 4*4 square and four 1*1
squares are required.

Example 2:

Input: L = 2, B = 4
Output: 2
Explaintion: Two 2*2 squares are enough to
fill the rectangle.

You do not need to read input or print anything. Your task is to complete the  function minSquares() which takes L and B as input parameters and returns minimum number of squares required to fill the rectangle. Return the answer modulo 109 + 7.

Expected Time Complexity: O(log(max(L, B)))
Expected Auxiliary Space: O(1)

Constraints:
1 ≤ L, B ≤ 1010

We are replacing the old Disqus forum with the new Discussions section given below.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

My Submissions:  