TopCoder problem "LongNumber" used in SRM 166 (Division I Level Three)



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

0)
    
1
Returns: 2
1)
    
5
Returns: 1
2)
    
78
Returns: 5
3)
    
1000000
Returns: 6
4)
    
1780243932
Returns: 1

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=1863

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=4635&pm=1863

Writer:

dimkadimon

Testers:

lbackstrom , brett1479

Problem categories:

Advanced Math