logo AlgoBeat OnlineJudge
登录 注册

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

内存限制:1024 MiB 时间限制:24000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

As you know, a complex number is often represented as the sum of a real part and an imaginary part. is such an example, where is the real part, is the imaginary part, and is the imaginary unit.

Given a prime number and a positive integer , 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 .
  • At least one of the real part and the imaginary part is not a multiple of .

For instance, when and , the complex numbers satisfying the conditions are (), (), and (), and the product of these numbers, that is, is .

输入格式

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

is a prime number less than . is a positive integer less than or equal to .

输出格式

Output two integers separated by a space in a line. When the product of all the complex numbers satisfying the given conditions is , the first and the second integers should be and , respectively. Here, means the integer between and , inclusive, such that is divisible by .

As exemplified in the main section, when and , the product to be calculated is . However, since , and are displayed in Sample Output 1.

样例

样例输入 1

3 1

样例输出 1

2 1

样例输入 2

5 5

样例输出 2

0 0

样例输入 3

499979 1000000000000000000

样例输出 3

486292 0