1236

题意:http://www.lightoj.com/volume_showproblem.php?problem=1236

解答:http://www.cnblogs.com/linliu/p/5549544.html

素数太大用bool

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define N 10000001
#define Lson rood<<1
#define Rson rood<<1|1
LL q[1000000];
bool a[N];
int k=0;
void prime()
{
    for(int i=2;i<N;i++)
    {
        if(!a[i])
        {
            q[k++]=i;
            for(int j=i;j<N;j+=i)
                a[j]=1;
        }
    }
}
LL pairsFormLCM(LL n)
{
    LL sum=1;
    for(int i=0;i<k&&q[i]*q[i]<=n;i++)
    {
        if(n%q[i]==0)
        {
            LL ans=0;
            while(n%q[i]==0)
            {
                n=n/q[i];
                ans++;
            }
            sum*=(2*ans+1);
        }
    }
    if(n>1)
        sum*=3;
    return sum/2+1;
}
int main()
{
    prime();
    int T,t=1;
    scanf("%d",&T);
    while(T--)
    {
        LL n;
        scanf("%lld",&n);
        printf("Case %d: %lld
",t++, pairsFormLCM(n));
    }
    return 0;
}
原文地址:https://www.cnblogs.com/a719525932/p/7808420.html