TopcoderArchiveVisit Topcoder
SRM2 May 2016
SRM 691

Undiv2

Problem statement, definition, constraints, and public examples.

Problem Statement

Given a positive integer x, let s(x) be the second smallest positive integer that does not divide x.

For example, let x = 6. The integers that do not divide x are 4, 5, 7, 8, 9, 10, ... The second smallest of these is 5. Hence we have s(6) = 5.

Hero took a blank sheet of paper. For each i between 1 and n, inclusive, he computed the value s(i) and wrote it on the paper. You are given the int n. Compute and return the sum of the n numbers on Hero's paper.

Definition

Class:
Undiv2
Method:
getsum
Parameters:
int
Returns:
long
Method signature:
long getsum(int n)
(be sure your method is public)

Constraints

  • n will be between 1 and 1,000,000,000, inclusive.

Examples

  1. 1
    Returns: 3
    The smallest two positive integers that don't divide 1 are 2 and 3. Thus, we have s(1) = 3.
  2. 2
    Returns: 7
  3. 3
    Returns: 11
    The answer is s(1) + s(2) + s(3) = 3 + 4 + 4 = 11.
  4. 5
    Returns: 19
  5. 8
    Returns: 32
  6. 13
    Returns: 53
Back to all problems