Answers for "Given n integers, your task is to report for each integer the number of its divisors. For example, if x=18, the correct answer is 6 because its divisors are 1,2,3,6,9,18."

C++
0

c++ find number of divisors

// https://www.geeksforgeeks.org/count-divisors-n-on13/
int countDivisors(int n) { 
    int cnt = 0; 
    for (int i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            // If divisors are equal, 
            // count only one 
            if (n / i == i) 
                cnt++; 
  
            else // Otherwise count both 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
}
Posted by: Guest on July-07-2020

Code answers related to "Given n integers, your task is to report for each integer the number of its divisors. For example, if x=18, the correct answer is 6 because its divisors are 1,2,3,6,9,18."

Browse Popular Code Answers by Language