TopcoderArchiveVisit Topcoder
SRM3 Apr 2006
SRM 296

EratosthenSieve2

Problem statement, definition, constraints, and public examples.

Problem Statement

Let N1 = {1, 2, 3, 4, 5, ..., 1000} (the set of all positive integers between 1 and 1000, inclusive).

Delete every second number in N1. The result is N2 = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, ..., 999}.

Delete every third number in N2. The result is N3 = {1, 3, 7, 9, 13, 15, 19, 21, 25, ..., 999}.

Delete every fourth number in N3. The result is N4 = {1, 3, 7, 13, 15, 19, 25, 27, ...}.

...

Delete every tenth number in N9. The result is N10. Find and return the n-th element of sequence N10, where n is a 1-based index.

Definition

Class:
EratosthenSieve2
Method:
nthElement
Parameters:
int
Returns:
int
Method signature:
int nthElement(int n)
(be sure your method is public)

Notes

  • N10 will contain exactly 101 elements.

Constraints

  • n will be between 1 and 100, inclusive.

Examples

  1. 3
    Returns: 7
  2. 1
    Returns: 1
  3. 10
    Returns: 79
  4. 25
    Returns: 223
Back to all problems