算数基本定理是个很基本的东西,他可以推导出很多东西;

http://acm.hust.edu.cn/vjudge/contest/79396#problem/H

把n分解成pi^ei然后算个数;

注意n比最大筛选的素数还要大点,所以要特判一次;

还有要判重复数的个数;

我好菜呀,我好菜呀,我好菜呀;

ac代码

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=1e7+5;
typedef long long ll;
bool prime[N];
int p[N/10];
ll k=0;
void Find_p()
{
    memset(prime,true,sizeof(prime));
    prime[1]=false;
    for(ll i=2;i<N;i++)
        if(prime[i])
    {
        p[k++]=i;
        for(ll j=i*i;j<N;j+=i)
            prime[j]=false;
    }
}
void get_ans(ll n)
{
    ll i=0;ll ans=1;
    while(n!=1&&i<k)
    {
        ll m=0;
        while(n%p[i]==0)
        {
            n=n/p[i];
            m++;
        }
        ans*=2*m+1;
        i++;
    }
    if(n>1) ans=ans*3;
    printf("%lld\n",ans/2+1);
}
int main()
{
    //freopen("input.txt","r",stdin);
    Find_p();
    int T;
    cin>>T;
    ll n;
    for(int cas=1;cas<=T;cas++)
    {
        scanf("%lld",&n);
        printf("Case %d: ",cas);
        get_ans(n);
    }
    return 0;
}