对于
P=p1^r1*p2^r2*.....*pn^rn,其中p1,p2,...,pn都是质数.
其因子个数为(r1+1)*(r2+1)*...*(rn+1)
1000内: 840 32
10000内: 7560 64
100000内: 83160 128
1000000内: 720720 240
10000000内: 8648640 448
可见10^7内的数,因子个数都不会太多。以后敢枚举了!!!
#include<stdio.h>
#include<string.h>
#include<math.h>
#define maxn 10000000
int b[maxn+10];
int s[maxn+10];
int tot;
int main()
{
for (int i=1;i<=maxn;i++)
s[i]=1;
memset(b,0,sizeof(b));
int i=2;
while (i<=maxn)
{
while (b[i] && i<=maxn)
i++;
int j=i+i;
while (j<=maxn)
{
int t = j;
int cnt = 1;
while (t%i==0)
{
cnt++;
t/=i;
}
s[j] *= cnt;
b[j]=1;
j+=i;
}
i++;
}
int maxs = 0,maxi;
for (int i=1;i<=maxn;i++)
if (s[i]>maxs)
maxs = s[i],maxi = i;
printf("%d %d\n",maxi,maxs);
return 0;
}