题目大意

题意

分析

g=gcd(a,b)g = gcd(a,b)

a=Aga = A*g

b=Bgb = B*g

(A,B)=1(A,B) = 1

lcm(a,b)=ab/(a,b)=ABglcm(a,b) = a*b/(a,b) = A*B*g

带入式子得

xABgyg=kx*A*B*g-y*g = k

g(xABy)=kg (x*A*B-y) = k

gg 可以通过枚举 kk 的因子得到

t=xAByt=x*A*B-y ,则

若能确定A,BA,B ,则可以唯一确定 a,ba,b,移项得

AB=(t+y)/xA*B = (t+y) / x , 注意到 (A,B)=1(A,B) = 1,说明 A,BA,B 中的质因子没有相同的

(t+y)/x(t+y)/x 的质因子种类数有 cntcnt 个,则贡献答案 2cnt2^{cnt}(考虑质因子分解给 AABB)

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
int p[20000005];
int st[20000005];
int cnt = 0;
void get()
{
st[1] = 1;
for (int i = 2; i <= 20000004; i++)
{
if (!st[i])
{
p[++cnt] = i;
st[i] = i;
}
for (int j = 1; j <= cnt && i * p[j] <= 20000005; j++)
{
if(!st[i * p[j]]){
st[i * p[j]] = p[j];
}
if (i % p[j] == 0)
break;
}
}
}


int x, y, k;

// 分解质因数的一个优化
int find(int x){
int cnt = 0;
while(x>1){
int t = st[x];
while(x % t == 0) x /= t;
cnt++;
}
if(x > 1) cnt++;
return cnt;
}

int cal(int t){
if((t+y)%x) return 0;
return (1ll <<(find((t+y)/x)));
}

signed main()
{
get();
int t;
cin >> t;
while (t--)
{
cin >> x >> y >> k;
int res = 0;
for (int i = 1; i <= k / i; i++)
{
if (k % i == 0){
res += cal(i);
if(i != k/i) res += cal(k/i);
}

}
cout << res << endl;
}
return 0;
}

质因数分解优化