TopcoderArchive
Archive
Algorithm problem

RepeatFreeSquares

Problem statement, definition, constraints, and public examples.

Problem Statement

Consider all squares of integers.

Among them, consider only those that contain no repeated digits in their base-10 representation.

Suppose we order them and number them starting from 0: the square 0 gets the index 0, the square 1 gets the index 1, the square 4 gets the index 2, and so on.

Given the int K, return the value at index K, or -1 if K is not a valid index.

Definition

Class:
RepeatFreeSquares
Method:
index
Parameters:
int
Returns:
long
Method signature:
long index(int K)
(be sure your method is public)

Constraints

  • K will be between 0 and 10^9, inclusive.

Examples

  1. 9
    Returns: 81
    The squares at indices 0 through 9 are 0, 1, 4, 9, 16, 25, 36, 49, 64, and 81.
  2. 10
    Returns: 169
    The squares 100, 121 and 144 each contain a repeated digit (0, 1, and 4, respectively). The next square in our sequence is therefore 169.
  3. 47
    Returns: 6084
Back to all problems