zoukankan      html  css  js  c++  java
  • Trailing Zeroes (I) LightOJ

    题目链接

    题意:求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
    ",++u,ans-1);
        }
    }
  • 相关阅读:
    敌兵布阵
    Points on Cycle
    Hero
    E~最少拦截系统
    C
    A
    J
    H
    G
    A
  • 原文地址:https://www.cnblogs.com/2462478392Lee/p/13681517.html
Copyright © 2011-2022 走看看