問題一覧 > 通常問題

No.2324 Two Countries within UEC

レベル : / AI推定難易度 : 1000 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 145
作問者 : sepa38 / テスター : phocom dyktr_06
お気に入りにしたユーザー ProblemId : 9549 / 自分の提出
問題文最終更新日: 2023-05-23 18:38:15
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
MMA Contest 015 (順位表) の他の問題:

Problem Statement

The Country of Sepa has $N$ towns, and the Country of Yakitori has $M$ towns. The towns of the Country of Sepa are numbered $1, 2, \cdots , N$, and the towns of the Country of Yakitori are numbered $1, 2, \cdots , M$. The friendship level between town $x$ of the Country of Sepa and town $y$ of the Country of Yakitori is $x \times y \mod P$.

You are given $Q$ queries. For the $i$-th query, output the number of towns in the Country of Yakitori whose friendship level with town $x_i$ of the Country of Sepa is $f_i$.

Input

$N \ M \ P \ Q$
$x_1\ f_1$
$x_2\ f_2$
$\ \ \ \ \vdots$
$x_Q\ f_Q$

Constraints

  • $1 \leq N, M \leq 10^9$
  • $2 \leq P \leq 10^9$
  • $1 \leq Q \leq 10^5$
  • $1 \leq x_i \leq N$
  • $0 \leq f_i \leq P - 1$
  • $P$ is prime
  • All inputs are integers

Output

On the $i$-th line, output the answer to the $i$-th query.

Sample

Sample 1
Input
5 5 11 3
2 8
4 7
5 3
Output
1
0
1

The only town with friendship level $8$ with town $2$ of the Country of Sepa is town $4$ of the Country of Yakitori, so output $1$. $\\$ No town in the Country of Yakitori has friendship level $7$ with town $4$ of the Country of Sepa, so output $0$. $\\$ The only town with friendship level $3$ with town $5$ of the Country of Sepa is town $5$ of the Country of Yakitori, so output $1$.

Sample 2
Input
85 82 17 8
55 1
23 2
31 7
83 0
8 0
76 16
32 1
14 1
Output
5
5
5
4
4
5
5
5

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。