All practice tasks

Coding (Algo)

Repeat a Modular Transform

Number theory · Medium

A deterministic numeric simulator applies the same multiplicative transformation many times and keeps only its remainder. The exponent can be too large to repeat the multiplication once per step. This is arithmetic practice, not a cryptographic implementation.

Return base raised to exponent modulo modulus as the canonical non-negative remainder.

Input

Call

  • Implement solve(input) and return the result. The provided adapter handles JSON input and output.

Input shape

{ base: integer, exponent: integer, modulus: integer }

Fields

  • base is a signed integer multiplier; exponent is a non-negative integer number of repetitions.
  • modulus is a positive integer.

Output

Return value

  • Return an integer from 0 through modulus - 1. Negative bases must use a non-negative remainder.
  • Exponent zero returns 1 modulo modulus, including base zero. Modulus one always returns zero.

Constraints

  • -1000000000 <= base <= 1000000000; 0 <= exponent <= 1000000000; 1 <= modulus <= 1000000000.
  • Multiplication can exceed safe Number precision. Use exact intermediate integer arithmetic.

Examples

Example 1

{
  "base": 3,
  "exponent": 4,
  "modulus": 10
}

Returns

1

Example 2

{
  "base": -2,
  "exponent": 3,
  "modulus": 5
}

Returns

2

Required complexity

O(log(exponent + 1)) exact-integer multiplications and O(1) accumulators

What this task practices

Repeat a Modular Transform is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.