โ† Capgemini questions
CodingReported in a candidate post, Sep 2021

Find the kth digit of a raised to power b

Filed under Capgemini

Free read 1 of 3

The 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

  1. Compute result = pow(a, b).

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.