就是枚举L与U之间的数,然后因式分解,divisor的数量即为其质因子按其阶数+1的乘积。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int a,b,c;
int prime[100000];
int vis[1000100];
void init()
{
memset(vis,0,sizeof(vis));
for(int i=2;i<=1000;i++) if(!vis[i])
{
for(int j=i*i;j<=1000000;j+=i) vis[j]=1;
}
c=0;
for(int i=2;i<=1000000;i++) if(!vis[i])
prime[c++]=i;
}
int divisor(int x)
{
int p=0;
int ans=1;
while(x!=1&&p<c)
{
int tmp=0;
while(x%prime[p]==0)
{
x/=prime[p];
tmp++;
}
ans*=(tmp+1);
p++;
}
if(x!=1) ans*=2;
return ans;
}
int main()
{
init();
int T;
cin>>T;
while(T--)
{
cin>>a>>b;
int ans,cnt=0;
for(int i=a;i<=b;i++)
{
int tmp=divisor(i);
if(tmp>cnt)
{
ans=i;cnt=tmp;
}
}
cout<<"Between "<<a<<" and "<<b<<", "<<ans<<" has a maximum of "<<cnt<<" divisors."<<endl;
}
return 0;
}