Mod Inverse When Coprime
Computer Mathematics
Hard
4 views
Problem Description
Given a and m, print inverse of a mod m, or -1 if not exists.
Input Format
Two integers a m.
Output Format
One integer inverse or -1.
Official Solution
Compute (g,x,_) from extended Euclid for (a,m). If g!=1 output -1 else inverse=(x%m+m)%m.
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!