#P14858. [ICPC 2021 Yokohama R] It' s Surely Complex

    ID: 16673 远端评测题 24000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学2021数论快速傅里叶变换 FFTICPC横浜

[ICPC 2021 Yokohama R] It' s Surely Complex

题目描述

As you know, a complex number is often represented as the sum of a real part and an imaginary part. 3+2i3 + 2i is such an example, where 33 is the real part, 22 is the imaginary part, and ii is the imaginary unit.

Given a prime number pp and a positive integer nn, your program for this problem should output the product of all the complex numbers satisfying the following conditions.

  • Both the real part and the imaginary part are non-negative integers less than or equal to nn.
  • At least one of the real part and the imaginary part is not a multiple of pp.

For instance, when p=3p = 3 and n=1n = 1, the complex numbers satisfying the conditions are 11 (=1+0i= 1 + 0i), ii (=0+1i= 0 + 1i), and 1+i1 + i (=1+1i= 1 + 1i), and the product of these numbers, that is, 1×i×(1+i)1 \times i \times (1 + i) is 1+i-1 + i.

输入格式

The input consists of a single test case of the following format.

p np\ n

pp is a prime number less than 5×1055 \times 10^5. nn is a positive integer less than or equal to 101810^{18}.

输出格式

Output two integers separated by a space in a line. When the product of all the complex numbers satisfying the given conditions is a+bia + bi, the first and the second integers should be amodpa \bmod p and bmodpb \bmod p, respectively. Here, xmodyx \bmod y means the integer zz between 00 and y1y-1, inclusive, such that xzx - z is divisible by yy.

As exemplified in the main section, when p=3p = 3 and n=1n = 1, the product to be calculated is 1+i-1 + i. However, since 1mod3=2-1 \bmod 3 = 2, 22 and 11 are displayed in Sample Output 1.

3 1
2 1
5 5
0 0
499979 1000000000000000000
486292 0