TopcoderArchiveVisit Topcoder
SRM16 May 2018
SRM 734

TheRoundCityDiv2

Problem statement, definition, constraints, and public examples.

Problem Statement

John and Brus have found a nice horizontal plane and they built a round city somewhere on the plane. The center of the city is at coordinates (0, 0). This point is left empty. There is a house at each other lattice point that is at most r units away from the city center. That is, the lattice point (x, y) other than (0, 0) contains a house if and only if sqrt(x*x + y*y) ≤ r.

John and Brus now want to count all houses in the city. You are given the int r. Return the number of houses.

Definition

Class:
TheRoundCityDiv2
Method:
find
Parameters:
int
Returns:
int
Method signature:
int find(int r)
(be sure your method is public)

Constraints

  • r will be between 1 and 100, inclusive.

Examples

  1. 1
    Returns: 4
    There are four houses in the city: (0, 1), (0, -1), (1, 0) and (-1, 0).
  2. 2
    Returns: 12
    There are twelve houses in the city: (0, 1), (0, -1), (1, 0), (-1, 0), (0, 2), (0, -2), (2, 0), (-2, 0), (1, 1), (1, -1), (-1, 1) and (-1, -1).
  3. 3
    Returns: 28
    There are twenty-eight houses in the city: (0, 1), (0, -1), (1, 0), (-1, 0), (0, 2), (0, -2), (2, 0), (-2, 0), (1, 1), (1, -1), (-1, 1), (-1, -1), (0, 3), (0, -3), (3, 0), (-3, 0), (1, 2), (1, -2), (-1, 2), (-1, -2), (2, 1), (2, -1), (-2, 1), (-2, -1), (2, 2), (2, -2), (-2, 2) and (-2, -2).
  4. 47
    Returns: 6920
Back to all problems