这道题是要求在多组数据中,分别求出每组数据中符合题目中所给定条件的数对(x, y)的个数。在每组数据中,给定k、P和Q三个数,求满足以下条件的数对(x, y)的个数:
k * gcd(x, y) = lcm(x, y)
P ≤ gcd(x, y) ≤ Q
答案对1000000007取模。
下面是用C语言给出的代码示例:
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h>
#define ll long long
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() { int T; scanf("%d", &T);
while (T--)
{
ll k, p, q;
scanf("%lld%lld%lld", &k, &p, &q);
ll ans = 0;
for (ll x = p; x <= q; x++)
{
ll y = k * x / gcd(x, k);
if (lcm(x, y) == k * gcd(x, y))
ans++;
}
printf("%lld\n", ans % 1000000007);
}
return 0;
}