Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Count Divisor in O(n^1/3)
- ll countDivisor(ll n) {
- ll ans = 1;
- int len = primeList.size(); // upto 10^6
- for (int i = 0; i < len; i++) {
- ll pNum = primeList[i];
- ll num = pNum*pNum*pNum*1LL;
- if (num > n)
- break;
- int cnt = 1;
- while (n%pNum==0) {
- n /= pNum;
- cnt++;
- }
- ans *= cnt;
- }
- ll sq = sqrt(n);
- if (isPrime(n)) //Y is prime, F(Y)=2
- ans *= 2;
- else if (sq*sq==n && isPrime(sq)) //Y is square of a prime number, F(Y)=3
- ans *= 3;
- else if (n!=1) //Y is product of two distinct prime numbers, F(Y)=4
- ans *= 4;
- return ans;
- }
- // 12 = 6 (1, 2, 3, 4, 6, 12)
- // 999999999999999989 = 2
- // 100000007700000049 = 4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement