You will write the method a computer uses to find the remainder of a huge power: repeated squaring. The checker compares your results with Python's own pow(a, k, m).
The idea. Write the exponent in binary. For example , so . The powers come from squaring again and again, and you reduce modulo after every step.
Your tasks.
power_mod(a, k, m). Keep a result and a base. While k > 0: if k is odd, multiply result by base; then square base and halve k with k // 2. Reduce modulo m every time.digit_sum_mod9(n). Return the sum of the digits of n, reduced modulo .last_two_digits(a, k). Return the last two digits of as a number from to , using power_mod.Run your code once to unlock the worked solution.
Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…