Skip to content

Commit 656586a

Browse files
Merge pull request #1 from swamini-jadhav/swamini-jadhav-patch-1
Count Axis-Aligned Unit Squares in Circle
2 parents e2a78d4 + b94ec74 commit 656586a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

maths/Drone_Domain.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Drone's Domain
2+
We call a square valid on a 2d coordinate plane if it satisfies the following conditions:
3+
4+
Area of the square should be equal to 1.
5+
All vertices of the square have integer coordinates.
6+
All vertices of square lie inside or on the circle of radius r, centered at origin.
7+
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.
8+
9+
Input Format
10+
The first line contains the integer r, the radius of the circle.
11+
12+
Constraints
13+
1 <= r <= 2 * 10^5
14+
Use a 64-bit integer type (like long long in C++ or long in Java) for sum calculations to prevent overflow.
15+
16+
Output Format
17+
Print the number of different squares in this circle of radius r.
18+
19+
Sample Input 1
20+
Sample Output 0"""
21+
22+
# Title: Count Axis-Aligned Unit Squares in Circle
23+
# Description: Counts the number of squares with area 1, integer vertices, fully inside a circle of radius r.
24+
25+
import sys
26+
import math
27+
28+
r=int(sys.stdin.readline())
29+
count=0
30+
for x in range(-r,r):
31+
for y in range(-r,r):
32+
# Check all four vertices are inside the circle
33+
if (x*x+y*y<=r*r and
34+
(x+1)*(x+1)+y*y<=r*r and
35+
x*x+(y+1)*(y+1)<=r*r and
36+
(x+1)*(x+1)+(y+1)*(y+1)<=r*r):
37+
count += 1
38+
39+
print(count)

0 commit comments

Comments
 (0)