因为b可以将C整除,所以可以得到b为C的因数。

因此可以直接枚举c的因数,从而确定a,b是否符合条件。
以下小编附上代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<deque>
#include<cmath>
#include<cstdio>
#define endl '\n'
//#define int long long
using namespace std;
typedef long long ll;
int k,c,n;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
bool check(int b){
    int a=(c-b)/k;
    if(a*k!=c-b) return false;
    if(gcd(a,b)<n||!a||!b) return false;
    return true;
}
void solve()
{
    cin>>k>>c>>n;
    int a,b;
    ll cnt=0;
    for(int i=1;i<=c/i;i++){
        b=i;
        if(c%b==0){
            if(check(b)) cnt++;
            if(b*b!=c&&check(c/b)) cnt++;
        }
    }
    cout<<cnt<<endl;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    cin>>t;
    while(t--)
        solve();
    return 0;
}