QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 256 MB 總分: 100

#15781. Key Cracking

统计

The key generation process for an asymmetric encryption algorithm is as follows:

  1. Choose two distinct prime numbers $p$ and $q$.
  2. Calculate $N = pq$ and $r = (p-1)(q-1)$.
  3. Select an integer $e$ such that $e < r$ and $\gcd(e, r) = 1$.
  4. Calculate an integer $d$ such that $ed \equiv 1 \pmod r$.
  5. The pair $(N, e)$ is called the public key, and the pair $(N, d)$ is called the private key.

When a message $n$ needs to be encrypted (assuming $n$ is an integer less than $N$, as any formatted message can be converted into an integer representation), use the public key $(N, e)$ and perform the operation: $$n^e \equiv c \pmod N$$ to obtain the ciphertext $c$.

To decrypt the ciphertext $c$, use the private key $(N, d)$ and perform the operation: $$c^d \equiv n \pmod N$$ to obtain the original message $n$. The proof of the algorithm's correctness is omitted.

Since ciphertext encrypted with a public key can only be decrypted with the corresponding private key and cannot be decrypted with the public key itself, it is called an asymmetric encryption algorithm. Typically, the public key is made public by the message recipient, while the private key is held by the recipient themselves. This allows anyone sending a message to encrypt it using the public key, while only the recipient can decrypt the message.

Your task is to find a feasible method to crack this encryption algorithm, i.e., to derive the private key from the public key and use it to decrypt the ciphertext.

Input

The input consists of a single line containing three space-separated positive integers $e, N, c$.

Output

The output consists of a single line containing two space-separated integers $d, n$.

Examples

Input 1

3 187 45

Output 1

107 12

Note 1

In the example, $p = 11, q = 17$.

Subtasks

For $30\%$ of the data, $e, N, c \leq 2^{20}$.

For $100\%$ of the data, $1 \leq e, N, c \leq 2^{62}, c < N$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.