Divisions

David is a young boy and he loves numbers. Recently he learned how to divide two numbers. David divides the whole day. He is happy if the result of the division is an integer, but he is not very amused if this is not the case. After quite a while he decided to use only a single dividend each day.

The parents of David are very careful and they would like to ensure that David experiences enough happiness. Therefore they decide which number David will use as the dividend for this day.

There is still a problem: The parents are not very good at math and don't know how to calculate the number of positive integral divisors for a given dividend N , which lead to an integral result. Now it's up to you to help David's parents.

Input Format

The single input line contains the single integer N , where N is chosen as a dividend (1 \le N \le 10^{18} ).

Output Format

Print the number of positive integral divisors of N that lead to an integral result of the division.

样例输入1

12

样例输出1

6

样例输入2

999999999999999989

样例输出2

2

样例输入3

100000007700000049

样例输出3

4

大数因子个数:

Pollard-Rho算法 随机算法  大佬传送门
AC代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 100001;
LL mul(LL a,LL b,LL mod) {
    if(!a) return 0;
    return ((a&1)*b%mod + (mul(a>>1,b,mod)<<1)%mod)%mod;
}
LL quickPow(LL a,LL d,LL n) {
    LL ret = 1;
    while(d) {
        if(d&1) ret = mul(ret,a,n);
        d >>= 1;
        a = mul(a,a,n);
    }
    return ret;
}
bool check(LL a,LL d,LL n) {
    if(n == a) return true;
    while(~d&1) d >>= 1;
    LL t = quickPow(a,d,n);
    while(d < n-1 && t != 1 && t != n-1) {
        t = mul(t,t,n);
        d <<= 1;
    }
    return (d&1) || t == n-1;
}
bool isP(LL n) {
    if(n == 2) return true;
    if(n < 2 || 0 == (n&1)) return false;
    static int p[5] = {2,3,7,61,24251};
    for(int i = 0; i < 5; ++i)
        if(!check(p[i],n-1,n)) return false;
    return true;
}
LL gcd(LL a,LL b) {
    if(a < 0) return gcd(-a,b);//特别注意,没这个TLE
    return b?gcd(b,a%b):a;
}
LL Pollard_rho(LL n,LL c) {
    LL i = 1,k = 2,x = rand()%n,y = x;
    while(true) {
        x = (mul(x,x,n) + c)%n;
        LL d = gcd(y - x,n);
        if(d != 1 && d != n) return d;
        if(y == x) return n;
        if(++i == k) {
            y = x;
            k <<= 1;
        }
    }
}
LL Fac[maxn],tot;
void factorization(LL n) {
    if(isP(n)) {
        Fac[tot++] = n;
        return;
    }
    LL p = n;
    while(p >= n) p = Pollard_rho(p,rand()%(n-1)+1);
    factorization(p);
    factorization(n/p);
}
map<LL,LL>ump; 
int main() {
    LL x;
    srand(time(0));
    while(~scanf("%lld",&x)){
        tot = 0;
        if(x == 1) {
            puts("1");
            continue;
        }
        if(isP(x)){
            puts("2");
            continue;
        }
        factorization(x);
        ump.clear();
        for(int i = 0; i < tot; ++i)
            ump[Fac[i]]++;
        LL  ret = 1;
    	for(int i=0;i<tot;i++)
    	{
    	    ret*=ump[Fac[i]]+1;
    		ump[Fac[i]]=0;
		}
        printf("%lld\n",ret);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/blackneed/article/details/81132071