由于穹妹很聪明,她的数学老师给她布置了一个作业,让她求出L到R之间不同因子数最多的那个数和这个数不同的因子个数(包含1和本身)。这个无聊的数学老师给出的L和R区间可能比较大,穹妹不想浪费时间在这种简单的问题上,她认为宝贵的时间应该更多的利用在和哥哥相处上,所以她向精通数学和计算机的你求助,希望你能帮她解决这个问题。
第一行:两个正整数L和R,保证L<=R
一行两个数,第一个数表示L到R之间因子数最多的那个数,第二个数表示该数的因子个数(包含1和本身)
1000 2000
1680 40
24的因子为:
1 24
2 12
4 6
3 8
只要求出左边就可以推算出右边(因数都是成对出现的)
不过也有例外:
这里只需要记一次就可以了
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
long long l,r,ans,maxx,ans2;
int main()
{
scanf("%lld%lld",&l,&r);
for (long long i=l; i<=r; ++i)
{
long long tt=sqrt(i);
for (long long j=1; j<=tt; ++j)
{
if (i%j==0 && j*j!=i) ans+=2;//一对的情况
else if (i%j==0) ans++;//单个的情况
}
if (maxx<ans) maxx=ans,ans2=i;//记录
ans=0;
}
printf("%lld",ans2);
printf(" %lld",maxx);
}