CodingReported in a candidate post, Sep 2021
Find the kth digit of a raised to power b
Filed under Capgemini
Free read 1 of 3The question
Given integers a, b, and k, calculate the k-th digit (from the right, 1-indexed) of a raised to the power of b.
Constraints
- a, b >= 0
- k > 0
- Resulting number may be very large
Examples
- Input
- a=2, b=3, k=1
- Output
- 8
- Why
- 2^3 = 8. The 1st digit from the right is 8.
Approach
Compute result = pow(a, b).
Convert result to string or use modulo/division: (result // 10^(k-1)) % 10.
Handle k larger than the number of digits by returning 0.
Tips
- What they are testing: Test with large b where a^b exceeds integer limits.
- Common mistake: Calculating the full number first, which can cause overflow in languages with fixed-size integers.
Related Capgemini questions
Collected from public candidate posts and coding forums. Updated Nov 2026.