PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SP0000277. Khôi phục khóa bí mật RSA (Cracking RSA)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Khôi phục khóa bí mật RSA (Cracking RSA)
Cracking RSA
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
An RSA public key is a pair . The integer is the product of two distinct primes and : . Define . The private exponent satisfies and . Given the public key , find its private exponent . The input guarantees that a unique valid exists.
Input
One line contains integers and , separated by a space. The number is the product of two distinct primes and .
Output
Print the integer , the required private exponent.
Subtasks
- Subtask 1 (20 points): for distinct primes ; ; ; .
- Subtask 2 (30 points): for distinct primes ; ; ; .
- Subtask 3 (50 points): for distinct primes ; ; ; .
Examples
Example 1
Input
33 3
Output
7
Explanation
Here , so , and . The private exponent satisfies . Since , the required exponent is , and the output is 7.
Example 2
Input
65 11
Output
35
Explanation
Here , so , and . We require . Since , the required private exponent is , and the output is 35.