Avatar ·

Modular multiplicative inverse of a modulo m

📁 Advanced Python Topics, example

Given two integers m and a. If the modular multiplicative inverse of a modulo m does not exist, output -1; if it exists, output this number (the answer must be in the range from 0 to m-1).

Input data: A single line of input contains two integers 1

Output data: Output the answer to the problem.

Examples: Input 179 57 Output 22

b = 0 a = list(map(int, input().split())) b = pow(a[1], a[0] - 2, a[0]) if pow(a[1                    
Avatar ·
  1. Separate process -- you should look at either the threading module or multiprocessing.
  2. You are not required to store all data in memory, and if it concerns string resources, you can use the ziplib module, or write and read data from a file in chunks.
  3. If you are reading from a file, you can store the zip file in memory -- the mmap module will help you.
  4. Using the cython extension will help you reduce memory consumption by 5-8 times and speed up your calculations by 5-140 times.
  5. An urgent request: duplicate your comments in Russian. Do not use complex specific constructs. Do not use hidden attributes (they are used for a different purpose).

Log in to leave an answer

Blogs