C2: Modular Inverse

Time Limit: 3 sec

Memory Limit: 512 MiB

Score: 300

Problem Statement

You are given two positive integers aa and LL that are coprime.

Calculate a1 mod La^{-1}\ \text{mod}\ L, where a1a^{-1} is a inverse of aa and is defined as an integer that satisfies aa11 (mod L)a \cdot a^{-1} \equiv 1\ (\text{mod}\ L).

Constraints

  • 1a<L210241 \leq a < L \leq 2^{1024}
  • The result must be returned as a integer variable
  • The submitted code must follow the specified format:
def solve(a: int, L: int) -> int:
    result: int = 0
    # Write your code here:
 
    return result

Hints

Open
  • LL is not necessarily a prime number.

Please sign in to submit your answer.