Given a circular sheet of radius, R. Find the total number of rectangles with integral length and width that can be cut from the sheet, one at a time.
Example 1:
Input:
R=1
Output:
1
Explanation:
Only 1 rectangle of dimensions 1x1.
Example 2:
Input:
R=2
Output:
8
Explanation:
The 8 possible rectangles are 
(1x1)(1x2)(1x3)(2x1)(2x2)(2x3)(3x1)(3x2).
Your Task:
You don't need to read input or print anything. Your task is to complete the function rectanglesInCircle() which takes an integer R as the radius and returns the number of rectangles that can fit on the circle.
Expected Time Complexity:O(R^{2})
Expected Auxillary Space:O(1)
Constraints:
1<=R<=1000

Source: geeksforgeeks | Difficulty: EASY
Tags: Geometry

Starter code: #User function template for Python

class Solution:
    def rectanglesInCircle(self,R):
        #code here

Solutions:
class Solution:

	def rectanglesInCircle(self, R):
		rec = 0
		d = 2 * R
		ds = d * d
		for i in range(1, 2 * R):
			for j in range(1, 2 * R):
				dl = i * i + j * j
				if dl <= ds:
					rec += 1
		return rec


class Solution:

	def rectanglesInCircle(self, R):
		c = 0
		d = R * 2
		for i in range(1, d):
			for j in range(1, d):
				if i * i + j * j <= d * d:
					c += 1
		return c


class Solution:

	def rectanglesInCircle(self, R):
		r2 = R * R * 4
		ans = 0
		for i in range(1, R * 2):
			l = i
			r = R * 2 - 1
			while l < r:
				m = (l + r) // 2
				v = i * i + m * m
				if v < r2:
					l = m + 1
				else:
					r = m
			if i * i + l * l > r2:
				l -= 1
			if l >= i:
				ans += 1 + 2 * (l - i)
		return ans


class Solution:

	def rectanglesInCircle(self, R):
		r2 = R * R * 4
		ans = 0
		for i in range(1, R * 2):
			a = i * i
			for j in range(i, R * 2):
				if a + j * j <= r2:
					ans += 1 if i == j else 2
				else:
					break
		return ans


class Solution:

	def rectanglesInCircle(self, r):
		x = 0
		for i in range(1, 2 * r + 1):
			for j in range(1, 2 * r + 1):
				if i * i + j * j <= 4 * r * r:
					x = x + 1
		return x