```
input
2
41 1 96 288
95 1 37 1776
output(把cnt定义全局变量)
6
8
right output(cntd定义在循环内)
6
2
```
by ninji @ 2023-05-15 19:20:04
```
#include<bits/stdc++.h>
using namespace std;
int T,a1,a0,b0,b1;
//int cnt=0;
int gcd(int x,int y)
{
return y?gcd(y,x%y):x;
}
int lcm( int x, int y)
{
return x/gcd(x,y)*y;
}
int main()
{ int cnt=0;
cin>>T;
while(T--)
{ cnt=0;
scanf("%d %d %d %d",&a0,&a1,&b0,&b1);
for(int i=1;i<=b1/i;i++)
if(b1%i==0)
{
if(gcd(i,a0)==a1 && lcm(i,b0)==b1)
cnt++;
if(b1/i!=i)
if(gcd(b1/i,a0)==a1 && lcm(b1/i,b0)==b1) cnt++;
}
printf("%d\n",cnt);
}
return 0;
}
```
全局cnt要清0
by Lovely_CCCyh___ @ 2023-05-15 19:28:51
因为如果你定义在外面的话他就会把上一次的累加上去,导致6, 8(直接加了2)的结果,所以要每次清零
by SunArrebol @ 2023-05-15 19:34:33
感谢@zhuangli123@_Fool_CYH_明白了
by ninji @ 2023-05-15 20:40:58
@[zhuangli123](/user/552975)
by ninji @ 2023-05-15 20:41:12
@[_Fool_CYH_](/user/772909)
by ninji @ 2023-05-15 20:41:26