From b94ec7419fa0f25fc0b539c6d216cb8dec8cb2e5 Mon Sep 17 00:00:00 2001 From: swamini-jadhav Date: Mon, 20 Oct 2025 15:15:43 +0530 Subject: [PATCH] Count Axis-Aligned Unit Squares in Circle Counts the number of squares with area 1, integer vertices, fully inside a circle of radius r. --- maths/Drone_Domain.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 maths/Drone_Domain.py diff --git a/maths/Drone_Domain.py b/maths/Drone_Domain.py new file mode 100644 index 000000000000..2916d57e1278 --- /dev/null +++ b/maths/Drone_Domain.py @@ -0,0 +1,39 @@ +"""Drone's Domain +We call a square valid on a 2d coordinate plane if it satisfies the following conditions: + +Area of the square should be equal to 1. +All vertices of the square have integer coordinates. +All vertices of square lie inside or on the circle of radius r, centered at origin. +Given the radius of circle r, count the number of different valid squares. Two squares are different if atleast one of the vertices of first square is not a vertex of second square. + +Input Format +The first line contains the integer r, the radius of the circle. + +Constraints +1 <= r <= 2 * 10^5 +Use a 64-bit integer type (like long long in C++ or long in Java) for sum calculations to prevent overflow. + +Output Format +Print the number of different squares in this circle of radius r. + +Sample Input 1 +Sample Output 0""" + +# Title: Count Axis-Aligned Unit Squares in Circle +# Description: Counts the number of squares with area 1, integer vertices, fully inside a circle of radius r. + +import sys +import math + +r=int(sys.stdin.readline()) +count=0 +for x in range(-r,r): + for y in range(-r,r): + # Check all four vertices are inside the circle + if (x*x+y*y<=r*r and + (x+1)*(x+1)+y*y<=r*r and + x*x+(y+1)*(y+1)<=r*r and + (x+1)*(x+1)+(y+1)*(y+1)<=r*r): + count += 1 + +print(count)