code
还是要提前做一下记忆优化,要不然会T
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#define fr(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
inline int read(){
int x = 0, op = 1; char ch = getchar();
while (!isdigit(ch)){ if (ch == '-') op = -1; ch = getchar();}
while (isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48), ch = getchar();}
return x * op;
}
const int N = 2e7 + 10;
const ll mod = 1e9 + 7;
int cnt[N+50];
//统计质因子个数
void eras(){
for(int i = 2; i <= N; i++){
if(cnt[i]) continue;
for(int j = i; j <= N;j += i){
cnt[j]++;
}
}
}
long long qpow(long long a, int b){
long long res = 1;
while (b != 0){
if (b & 1){
res = res * a;
res %= mod;
}
a = a * a;
b >>= 1;
}
return res % mod;
}
void solve(){
int c = read(), d = read(), x = read();
long long ans = 0;
for (int i = 1; i * i <= x; ++i) {
if (x % i == 0){
if ((i + d) % c == 0){
int kk = (i + d) / c;
ans += qpow(2, cnt[kk]);
}
if (((x / i) + d ) % c == 0 && x / i != i){
int kk = (x / i + d) / c;
ans += qpow(2, cnt[kk]);
}
ans %= mod;
}
}
printf("%lld\n", ans);
}
int main() {
eras();
int cases = read();
while (cases--){
solve();
}
return 0;
}