为什么是WA呢,TLE我还能理解
查看原帖
为什么是WA呢,TLE我还能理解
833124
BIOS楼主2023/12/14 13:05
#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了呢。。。

2023/12/14 13:05
加载中...