#include <iostream>
#include <cmath>
#include <set>
using namespace std;
const int N = 1e4 + 5;
int t, l, r, lim, p, res, n;
set<int> ac[N];
signed main()
{
cin >> t;
while (t--)
{
cin >> l >> r, n = r - l, lim = sqrt(r), res = 0;
for (int i = 0; i <= n; i++)
ac[i].clear();
for (int i = 2; i <= lim; i++)
for (int now = (l / i) * i; now <= r; now += i)
if (now >= l && now <= r)
ac[now - l].insert(i), ac[now - l].insert(now / i);
for (int i = 0; i <= n; i++)
if (res < ac[i].size())
res = ac[i].size(), p = i;
printf("Between %d and %d, %d has a maximum of %d divisors.\n", l, r, p + l, res + 2);
}
}
这做法跑Udebug会超时,但是测得结果都是对的,直觉上也觉得这么做很慢但是没错,为什么WA了呢。。。