Mod Inverse | 프로그래밍의 벗 PivotOJ
PivotOJ

Mod Inverse

시간 제한: 1000ms메모리 제한: 128MB출처: CCC 2001 JuniorBOJ 6930

문제

In many cryptographic applications, the Modular Inverse is a key point. This question involves finding the modular inverse of a number.

Given 0<x<m0 < x < m, where xx and mm are integers, the modular inverse of xx is the unique integer nn, 0<n<m0 < n < m, such that the remainder upon dividing x×nx \times n by mm is 11.

For example, 4×13=52=17×3+14 \times 13 = 52 = 17 \times 3 + 1, so the remainder when 5252 is divided by 1717 is 11, and thus 1313 is the inverse of 44 modulo 1717.

You are to write a program which accepts as input the two integers xx and mm, and outputs either the modular inverse nn, or the statement No such integer exists. if there is no such integer nn.

예제

예제 1

입력
4
17
출력
13

예제 2

입력
6
10
출력
No such integer exists.
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.