Statistics

Problem Statement for "TwoTurtledoves"

Problem Statement

I give my true love presents every day. On day 1, I give her one Type 1 present. On day 2, I give her two Type 2 presents, followed by one Type 1 present. On day 3, I give her three Type 3 presents, followed by two Type 2 presents, followed by one Type 1 present. This pattern continues day after day. Soon I begin to wonder, what type of present will be the 100th present that I give my true love? The 1000th? The 1000000th?

For example, the 10th present that I give my true love is the Type 1 present on day 3.

Write a method that takes an int n and returns the type of the nth present that I give my true love. Note that n is one-based, so n=1 refers to the very first present I give her (the Type 1 present on day 1).

Definition

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

Notes

  • Unlike the poseur in the popular Christmas song, I do not stop giving my true love presents after the 12th day.

Constraints

  • n is between 1 and 1000000000, inclusive.

Examples

  1. 10

    Returns: 1

    The example above.

  2. 12

    Returns: 4

    The second of four Type 4 presents on Day 4.

  3. 399

    Returns: 11

  4. 123456

    Returns: 65

  5. 1000000000

    Returns: 1704

  6. 15

    Returns: 3

  7. 97

    Returns: 7

  8. 132

    Returns: 8

  9. 567

    Returns: 15

  10. 901

    Returns: 12

  11. 1500

    Returns: 9

  12. 2340

    Returns: 23

  13. 5007

    Returns: 30

  14. 8102

    Returns: 26

  15. 13975

    Returns: 21

  16. 20311

    Returns: 32

  17. 50273

    Returns: 65

  18. 97263

    Returns: 55

  19. 412412

    Returns: 117

  20. 888888

    Returns: 93

  21. 1034512

    Returns: 86

  22. 6972342

    Returns: 321

  23. 11927654

    Returns: 376

  24. 24000101

    Returns: 484

  25. 56562342

    Returns: 481

  26. 154392485

    Returns: 410

  27. 334789098

    Returns: 627

  28. 529834211

    Returns: 1155

  29. 912120634

    Returns: 1525

  30. 999999999

    Returns: 1704

  31. 999800616

    Returns: 1

  32. 999800617

    Returns: 1817

  33. 1

    Returns: 1

  34. 2

    Returns: 2

  35. 3

    Returns: 2

  36. 4

    Returns: 1

  37. 1000000000

    Returns: 1704

  38. 10

    Returns: 1

  39. 1

    Returns: 1

  40. 12

    Returns: 4

  41. 2323

    Returns: 24

  42. 4

    Returns: 1


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: