#Lutece3021. 简单数论 2

简单数论 2

Migrated from Lutece 3021 简单数论 2

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

这是一道简单的数论题,至少它的题面很简单。

给出若干组正整数 ppxx,求方程 a2+b2x(modp)a^2+b^2\equiv x\pmod p 关于 aabb 在模 pp 意义下解的组数。其中 pp 是奇数且不含平方因子。

Input

第一行包括一个正整数 t(1t105)t(1\leq t\leq 10^5),表示询问组数。

接下来 tt 行每行包括两个正整数 p,x(0xp1,p107)p,x(0\leq x\leq p-1,p\leq 10^7)

Output

输出 tt 行,第 ii 行包括一个正整数,代表第 ii 个方程解的组数。

Samples

1
5 0
9

Note

99 组解分别为 $(a,b) = (0,0),(1,2),(1,3),(2,1),(2,4),(3,1),(3,4),(4,2),(4,3)$。

Resources

2023 UESTC ICPC Training for Math