|
- //CodeVS数据有错
- #include <iostream>
- using namespace std;
- const int pNum = 20;
- const int p[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 71};
- int l, r;
- int ans = 1 << 30;
- int now = 0;
- void dfs(int i, int s, long long n)
- {
- if (n > r || i >= 12)
- return;
- if (n >= l)
- if ((s == now && n < ans) || s > now)
- {
- ans = n;
- now = s;
- }
- int k = 1;
- while (n < r)
- {
- dfs(i+1, s * k, n);
- ++k;
- n *= p[i];
- }
- }
- int cal(int n)
- {
- int i = 2, k = 1, sum = 1;
- while (n != 1)
- {
- if (n % i == 0)
- {
- n /= i;
- ++k;
- }
- else
- {
- sum *= k;
- k = 1;
- ++i;
- }
- }
- sum *= k;
- return sum;
- }
- int main()
- {
- cin >> l >> r;
- if (r - l <= 100000)
- //此处应加判断,区间较小时直接计算,否则有可能错解,如l=r且为两大质数之积
- for (int i = l; i <= r; ++i)
- {
- int x = cal(i);
- if (x > now)
- {
- now = x;
- ans = i;
- }
- }
- else
- dfs(0, 1, 1);
- cout << "Between " << l << " and " << r << ", " << ans << " has a maximum of " << now << " divisors." << endl;
- return 0;
- }
复制代码 |
|