思路:
最终就是求一个数的约数(除了1)对吧.
然后想要枚举sqrt(N)受阻,枚举素数数组受阻,加上prime[i]*prime[i]<=n就好了?那就好了吧。
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL prime[1000100];
bool IsPrime[1000100];
int num;
void init_prime()
{
num=0;
memset(IsPrime,false,sizeof(IsPrime));
for(LL i=2;i<=1000000;i++)
{
if(IsPrime[i]) continue;
prime[num++]=i;
for(LL j=i+i;j<=1000000;j+=i)
IsPrime[j]=true;
}
}
LL solve(LL n)
{
LL ans=1,sum;
for(int i=0;i<num&&prime[i]*prime[i]<=n;i++)
{
LL tmp=prime[i];
sum=0;
if(n%tmp==0)
{
while(n%tmp==0)
{
n/=tmp;
sum++;
}
ans*=(sum+1LL);
}
}
if(n>1) ans*=2;
return ans-1;
}
int main()
{
int cas=1,T;
LL n;
init_prime();
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
printf("Case %d: %lld\n",cas++,solve(n));
}
return 0;
}