Statistics

Problem Statement for "LongNumber"

Problem Statement

We generate two infinitely long numbers. The first number is generated by writing down all positive consecutive integers, while the second is generated by writing down all of their squares. We then find the sum of these two numbers. Here are the first 33 digits of the calculation:

  123456789101112131415161718192021...
+ 149162536496481100121144169196225...
= 272619325597593231536305887388246...

The first digit of the result is 2, the second digit is 7, the third is 2 and so on.

Given an int k, return the digit at position k of the resulting number, where the first digit is at position 1.

Definition

Class:
LongNumber
Method:
findDigit
Parameters:
int
Returns:
int
Method signature:
int findDigit(int k)
(be sure your method is public)

Constraints

  • k will be between 1 and 2147483647 inclusive.

Examples

  1. 1

    Returns: 2

  2. 5

    Returns: 1

  3. 78

    Returns: 5

  4. 1000000

    Returns: 6

  5. 83916724

    Returns: 8

    followed by 8 9's with overflow

  6. 147538842

    Returns: 0

    followed by 7 9's with overflow

  7. 117250829

    Returns: 5

    followed by 7 9's with overflow

  8. 10502158

    Returns: 7

    followed by 7 9's with overflow

  9. 582536

    Returns: 5

    followed by 5 9's with overflow

  10. 379810

    Returns: 3

    followed by 5 9's with overflow

  11. 68708

    Returns: 1

    followed by 5 9's without overflow

  12. 2147483647

    Returns: 8

  13. 1780243932

    Returns: 1

  14. 1899805428

    Returns: 2

  15. 1741917165

    Returns: 7

  16. 1784488481

    Returns: 9

  17. 279893794

    Returns: 5

  18. 1471313522

    Returns: 0

  19. 97180482

    Returns: 4

  20. 857168575

    Returns: 7

  21. 2037788404

    Returns: 1

  22. 1443451632

    Returns: 2

  23. 1583394900

    Returns: 6

  24. 1244572457

    Returns: 8

  25. 843563866

    Returns: 0

  26. 2093151432

    Returns: 9

  27. 1391343239

    Returns: 9

  28. 31235306

    Returns: 2

  29. 1666328478

    Returns: 1

  30. 507134574

    Returns: 7

  31. 133689063

    Returns: 6

  32. 1458700812

    Returns: 2

  33. 2147483646

    Returns: 5

  34. 2147483645

    Returns: 2

  35. 1780243932

    Returns: 1

  36. 2147483647

    Returns: 8

  37. 582536

    Returns: 5

  38. 2147483600

    Returns: 9

  39. 22

    Returns: 3

  40. 59

    Returns: 2


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: