Problem Statement
After the process was over, Limak computed the sum of all numbers that appeared on the blackboard, including the original number X.
For example, if the original number was 509, the numbers that appeared on the blackboard were the numbers 509, 50, and 5. Their sum is 564.
You are given a
Definition
- Class:
- LastDigit
- Method:
- findX
- Parameters:
- long
- Returns:
- long
- Method signature:
- long findX(long S)
- (be sure your method is public)
Constraints
- S will be between 1 and 10^18, inclusive.
Examples
564
Returns: 509
This is the example from the problem statement. The value X = 509 produces the sum 564, as shown above.
565
Returns: -1
There is no X for which the sum would be 565.
3000
Returns: 2701
You can check that 2701 + 270 + 27 + 2 = 3000.
137174210616796
Returns: 123456789555123
837592744927492746
Returns: -1
999999999999999999
Returns: 900000000000000000
1367758989
Returns: 1230983094
45865856567567
Returns: 41279270910816
679674734645
Returns: 611707261185
58491090301390
Returns: 52641981271257
10
Returns: -1
1
Returns: 1
2
Returns: 2
3
Returns: 3
4
Returns: 4
5
Returns: 5
6
Returns: 6
7
Returns: 7
8
Returns: 8
9
Returns: 9
10
Returns: -1
11
Returns: 10
1000000000000000000
Returns: 900000000000000001
99999999999999999
Returns: 90000000000000000
99999999999999998
Returns: -1
99999999999999997
Returns: -1
99999999999999996
Returns: -1
99999999999999995
Returns: -1
99999999999999994
Returns: -1
99913239999999
Returns: 89921916000004
43242341352
Returns: 38918107221
141234124325
Returns: 127110711897
42523423532
Returns: 38271081183
10000234234
Returns: 9000210813
88776443108868985
Returns: 79898798797982099
333333333333333315
Returns: 299999999999999999
26
Returns: 24
472956193893217459
Returns: 425660574503895721