Given an integer R which represents the radius of a circle that has (0,0) as its centre, find the total number of lattice points on the circumference. Lattice Points are points with coordinates as integers in 2-D space.
Example 1:
Input: R = 5
Output: 12
Explanation: (0,5), (0,-5), (5,0), 
(-5,0), (3,4), (-3,4), (-3,-4), (3,-4), 
(4,3), (-4,3), (-4,-3), (4,-3).
Example 2:
Input: R = 88
Output: 4
Explanation: (0,88), (88,0), (0,-88), 
(-88,0)
Your Task:  
You don't need to read input or print anything. Your task is to complete the function latticePoints() which takes R as input and returns the number of lattice points.
Expected Time Complexity: O(RsqrtR)
Expected Auxiliary Space: O(1)
Constraints:
0 ≤ R ≤ 10^{4}

Source: geeksforgeeks | Difficulty: EASY
Tags: Geometry

Starter code: #User function Template for python3



class Solution:

    def latticePoints(self, r):

        # code here 

Solutions:
import math

class Solution:

	def latticePoints(self, r):
		if r == 0:
			return 0
		count = 4
		for i in range(1, r):
			t = math.sqrt(r * r - i * i)
			if t == int(t):
				count += 4
		return count


import math

class Solution:

	def latticePoints(self, r):
		if r == 0:
			return 0
		lattice_count = 2
		for i in range(-r + 1, r):
			x = i
			y = math.sqrt(r ** 2 - x ** 2)
			if y == int(y):
				lattice_count += 2
		return lattice_count


import math

class Solution:

	def latticePoints(self, r):
		if r == 0:
			return 0
		count2 = 0
		for i in range(1, r):
			a = r * r - i * i
			if math.sqrt(a) - math.floor(math.sqrt(a)) == 0:
				count2 = count2 + 1
		return 4 + count2 * 4


class Solution:

	def latticePoints(self, r):
		import math
		if r == 0:
			result = 0
		else:
			result = 4
			for i in range(1, r):
				ysq = r * r - i * i
				y = int(math.sqrt(ysq))
				if ysq == y * y:
					result += 4
		return result


import math

class Solution:

	def latticePoints(self, r):
		if r <= 0:
			return 0
		a = 4
		for x in range(1, r):
			ys = r * r - x * x
			y = int(math.sqrt(ys))
			if y * y == ys:
				a += 4
		return a


import math

class Solution:

	def latticePoints(self, r):
		c = 4
		if r <= 0:
			return 0
		else:
			for x in range(1, r):
				a = r * r - x * x
				b = int(math.sqrt(a))
				if a == b * b:
					c += 4
		return c


class Solution:

	def latticePoints(self, r):
		if r == 0:
			return 0
		x = 0
		for i in range(r + 1):
			if int((r ** 2 - i ** 2) ** 0.5) ** 2 + i ** 2 == r ** 2:
				if i == 0 or r * r - i * i == 0:
					x = x + 2
				else:
					x = x + 4
		return x