Statistics

Problem Statement for "CrazySequence"

Problem Statement

Consider the following infinite sequence of numbers: 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, ... (number k appears exactly k times in the sequence). You are given a String n representing an integer (without leading zeros). Return the n-th number in that sequence (index will be 1-based).

Definition

Class:
CrazySequence
Method:
nthNumber
Parameters:
String
Returns:
int
Method signature:
int nthNumber(String n)
(be sure your method is public)

Constraints

  • n will represent an integer between 1 and 1018, inclusive.
  • n will have no leading zeros.

Examples

  1. "1"

    Returns: 1

  2. "4"

    Returns: 3

  3. "169"

    Returns: 18

  4. "1000000000000000000"

    Returns: 1414213562

  5. "1234678901234567"

    Returns: 49692633

  6. "25342536783"

    Returns: 225133

  7. "5234523"

    Returns: 3236

  8. "8473524234"

    Returns: 130181

  9. "85965734523"

    Returns: 414646

  10. "87345234242"

    Returns: 417960

  11. "500500"

    Returns: 1000

  12. "500501"

    Returns: 1001

  13. "762078456028"

    Returns: 1234567

  14. "762078456029"

    Returns: 1234568

  15. "762078938126809995"

    Returns: 1234567890

  16. "762078938126809996"

    Returns: 1234567891

  17. "487730529388812681"

    Returns: 987654321

  18. "487730529388812682"

    Returns: 987654322

  19. "617283951049382716"

    Returns: 1111111111

  20. "617283951049382717"

    Returns: 1111111112

  21. "499999999500000000"

    Returns: 999999999

  22. "499999999500000001"

    Returns: 1000000000

  23. "946750935937596749"

    Returns: 1376045738

  24. "843958306720663067"

    Returns: 1299198450

  25. "937597734485037593"

    Returns: 1369377767

  26. "630583067355937446"

    Returns: 1123016534

  27. "783957204759274859"

    Returns: 1252163891

  28. "485768263748792736"

    Returns: 985665525

  29. "937496847396836274"

    Returns: 1369304091

  30. "386958473859604859"

    Returns: 879725496

  31. "123456789"

    Returns: 15713

  32. "999999999999999924"

    Returns: 1414213562

  33. "2500"

    Returns: 71


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: