Connection Status:
Competition Arena > LongNumber
SRM 166 · 2003-10-01 · by dimkadimon · Advanced Math
Class Name: LongNumber
Return Type: int
Method Name: findDigit
Arg Types: (int)
Problem Statement

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.

Constraints

  • k will be between 1 and 2147483647 inclusive.
Examples
0)
1
Returns: 2
1)
5
Returns: 1
2)
78
Returns: 5
3)
1000000
Returns: 6
4)
83916724
Returns: 8

followed by 8 9's with overflow

5)
147538842
Returns: 0

followed by 7 9's with overflow

6)
117250829
Returns: 5

followed by 7 9's with overflow

7)
10502158
Returns: 7

followed by 7 9's with overflow

8)
582536
Returns: 5

followed by 5 9's with overflow

9)
379810
Returns: 3

followed by 5 9's with overflow

10)
68708
Returns: 1

followed by 5 9's without overflow

Submissions are judged against all 40 archived test cases, of which 11 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class LongNumber with a public method int findDigit(int k) · 40 test cases · 2 s / 256 MB per case

Submitting as anonymous