打字不方便,还是写字吧!
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
long long ex_gcd(long long a,long long b,long long &x,long long &y){
if(b==0){
x=1;
y=0;
return a;
}
long long fz=ex_gcd(b,a%b,x,y);
long long temp=x;
x=y;
y=temp-(a/b)*y;
return fz;
}
int main(){
int t;
cin>>t;
while(t--){
long long n,a,b;
long long x,y;
scanf("%lld%lld%lld",&n,&a,&b);
long long d=ex_gcd(a,b,x,y);
if((n+1)%d!=0){
cout<<0<<endl;
}
else{
x=x*(n+1)/d;
long long lcm=a*b/d;
long long t1=lcm/a;
long long t2=lcm/b;
x%=t1;
if(x<=0){
x+=t1;
}
long long s=n-x*a;
if(s<0){
cout<<"0"<<endl;
}
else{
cout<<1+s/lcm<<endl;
}
}
}
return 0;
}