TopcoderArchive
Archive
Algorithm problem

CountLatticePoint

Problem statement, definition, constraints, and public examples.

Problem Statement

Consider a two dimensional plane.

Given an int N, return the number of lattice points whose Manhattan distance from (0, 0) is strictly less than N (including the point (0, 0).)

Here's the example for small cases. The center point in each case is (0, 0).
                                .
                      .        ...
            .        ...      .....
  .        ...      .....    .......
            .        ...      .....
                      .        ...
                                .

N = 1     N = 2     N = 3     N = 4

Definition

Class:
CountLatticePoint
Method:
count
Parameters:
int
Returns:
int
Method signature:
int count(int N)
(be sure your method is public)

Constraints

  • N will be between 1 and 100, inclusive.

Examples

  1. 1
    Returns: 1
    Described in problem statement.
  2. 2
    Returns: 5
  3. 3
    Returns: 13
  4. 4
    Returns: 25
  5. 95
    Returns: 17861
Back to all problems