#P4358. [CQOI2016] 密钥破解

    ID: 3288 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016重庆各省省选递归素数判断,质数,筛法逆元

[CQOI2016] 密钥破解

Description

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

  1. Choose two distinct prime numbers p,qp, q.
  2. Compute N=p×qN=p \times q, r=(p1)(q1)r=(p-1)(q-1).
  3. Select an integer ee that is less than rr and coprime with rr.
  4. Compute an integer dd such that ed1(modr)ed≡1(mod r).
  5. The ordered pair (N,e)(N,e) is called the public key, and the ordered pair (N,d)(N,d) is called the private key.

When encrypting a message nn (assume nn is an integer less than NN, because any format of message can be converted to an integer), use the public key (N,e)(N,e) and compute

nec(modN)n^e≡c(mod N)

to obtain the ciphertext cc.

To decrypt the ciphertext cc, use the private key (N,d)(N,d) and compute

cdn(modN)c^d≡n(mod N)

to obtain the original plaintext nn. The proof of correctness is omitted.

Because ciphertext encrypted with the public key can only be decrypted with the corresponding private key, and not with the public key itself, this is called an asymmetric encryption algorithm. Typically, the public key is published by the message receiver, while the private key is kept by the receiver. In this way, anyone can encrypt messages using the public key, but only the receiver can decrypt them.

Now your task is to find a feasible method to crack this encryption algorithm: derive the private key from the public key and then use it to decrypt the ciphertext.

Input Format

The input contains a single line with three positive integers e,N,ce, N, c separated by spaces.

Output Format

Output a single line with two integers d,nd, n separated by a space.

3 187 45
107 12

Hint

  • For 30%30\% of the testdata, e,N,c220e, N, c \le 2^{20}.
  • For 100%100\% of the testdata, e,N,c262,c<Ne, N, c \le 2^{62}, c < N.

Translated by ChatGPT 5