Number of unique rectangles
Basic Accuracy: 54.02% Submissions: 50 Points: 1

You are given N unit squares (squares with side length 1 unit), the task is to make rectangles using these squares and to count the number of rotationally unique rectangles. Two rectangles are rotationally unique if one can’t be rotated to become equivalent to the other one.


Example 1:

N = 4
Total rectangles we can make from 4
unit squares are: 1x1, 1x2, 1x3, 2x2,
1x4, 2x1, 3x1, and 4x1.
But we can get 2x1, 3x1, 4x1
by rotating 1x2, 1x3, 1x4.
So these five rectangles are rotationally unique.
1x1, 1x2, 2x2, 1x3 and 1x4.

Example 2:

N = 5
We can make only 6 rotationally unique
rectangles from 5 unit squares.


Your Task:
You don't need to read input or print anything. Your task is to complete the function noOfUniqueRectangles() which takes an Integer N as input and returns the answer.


Expected Time Complexity: O(N*sqrt(N))
Expected Auxiliary Space: O(1)


1 <= N <= 106

We are replacing the old Disqus forum with the new Discussions section given below.
Click here to view old Disqus comments.

to report an issue on this page.


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


All Submissions

My Submissions:

Login to access your submissions.

Number of unique rectangles

Output Window