what is complexity of following code and why? -
number of divisor using prime factorization. code:
include
using namespace std;
vector<int> primes; // we'll preload primes once @ beginning int countdivisor(int n) { int divisor = 1; (int = 0; < primes.size(); i++) { if (n % primes[i] == 0) { int cnt = 1; while (n % primes[i] == 0) { n /= primes[i]; cnt++; } divisor *= cnt; } } return divisor; }
Comments
Post a Comment