PowerDigit
TCO06 Sponsor 2 · 2006-03-01 · by dgoodman
Problem Statement
Create a class PowerDigit that contains a method digitK that is given x, y, and k and that returns the k-th digit (an integer in the range 0 to 9 inclusive) in x to the power y. If there is no k-th digit in x to the power y return -1.
Constraints
- x is between 0 and 10,000, inclusive.
- y is between 1 and 10,000, inclusive.
- k is between 0 and 4, inclusive.
2 10 1 Returns: 2
2^10 = 1024 so the digit 1 is 2.
2 10 4 Returns: -1
1024 does not have a digit 4 (the 1 in 1024 is digit 3)
2 1000 0 Returns: 6
2^1000 is a very large number. But digit 0 is predictable since with succeeding powers it follows the sequence 2, 4, 8, 6, 2, 4, 8, 6, 2, ....
10 2 1 Returns: 0
10 10 1 Returns: 0
Submissions are judged against all 119 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class PowerDigit with a public method int digitK(int x, int y, int k) · 119 test cases · 2 s / 256 MB per case