TopCoder problem "GridPointsOnCircle" used in SRM 260 (Division I Level One , Division II Level Two)



Problem Statement

    

You will be given rSquare, the square of the radius of a circle. You are to return the number of lattice points (points with integer coordinates) that lie on the circumference of a circle with this radius centered at the origin of the (cartesian) coordinate system.

 

Definition

    
Class:GridPointsOnCircle
Method:countPoints
Parameters:int
Returns:int
Method signature:int countPoints(int rSquare)
(be sure your method is public)
    
 

Constraints

-rSquare will be between 1 and 2,000,000,000, inclusive.
 

Examples

0)
    
1
Returns: 4
A circle with radius 1 centered at the origin goes through 4 lattice points: (1,0), (0,1), (-1,0) and (0,-1).
1)
    
25
Returns: 12
A circle with radius 5 goes through the points (+/-3, +/-4), (+/-4, +/-3), (0, +/-5) and (+/-5, 0) (12 points).
2)
    
3
Returns: 0
No lattice point is at distance sqrt(3) from the origin.
3)
    
44
Returns: 0
4)
    
50
Returns: 12

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=4766

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7994&pm=4766

Writer:

gepa

Testers:

PabloGilberto , lbackstrom , brett1479 , Olexiy

Problem categories:

Brute Force, Geometry, Simple Math