Trailing Zeroes (I) LightOJ - 1028(唯一分解定理)

题目链接

题意:求n大于2的因子个数。n<=1e12

思路:先打表1e6的因子个数吗,然后对n进行素因子分解,然后用唯一分解定理求出答案。因为没有很快想到故记录。

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<map>
#include<vector>
#include<algorithm>
#define N 2000600
#define ll long long
#define ull unsigned long long 
using namespace std;
int prime[N],vis[N];
int main()
{
    int t,u=0;
    int k=0;
    for(int i=2;i<=1000000;i++)
    {
        if(!vis[i]){
            prime[k++]=i;
        for(int j=i+i;j<=1000000;j+=i)
        {
            vis[j]=1;
        }
        }
    }
    scanf("%d",&t);
    while(t--)
    {
        ll n;
        scanf("%lld",&n);
        ll ans=1;
        for(int i=0;i<k&&prime[i]*prime[i]<=n;i++)
        {
            int x=prime[i];
            ll y=0;
            while(n%x==0)
            {
                n/=x;
                y++;
            }
            ans*=(y+1);
        }
        if(n>1)
        {
            ans*=2;
        }
        printf("Case %d: %lld\n",++u,ans-1);
    }
}

 

posted @ 2020-09-16 21:23  Ldler  Views(141)  Comments(0Edit  收藏  举报