Additive and multiplicative inverses
InterviewTime limit1sMemory limit128 MB
Given N and A, print the additive inverse of A modulo N and the multiplicative inverse if it exists, otherwise -1.
- Level
Medium4 of 10
- Topics
- Number theory, Math, Implementation
- Solved
- No attempts yet
Problem
Let be the set of integers from to . For , is the additive inverse of if , and is the multiplicative inverse of if .
You are given integers and . Find the additive inverse and the multiplicative inverse of in . If the multiplicative inverse does not exist, print for it.
Input
The first line contains () and (), separated by a space.
Output
Print the additive inverse and the multiplicative inverse of in on one line, separated by a space. If the multiplicative inverse does not exist, print in its place.
Both inverses are integers in the range to , and each of them is unique when it exists.
Hint
For and , the additive inverse is because , and the multiplicative inverse is because .