Count Divisors of n in O ( n ^ 1 / 3 ) | C implementation of Naive method to count all divisors ; function to count the divisors ; If divisors are equal , count only one ; else Otherwise count both ; Driver program to test above function
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countDivisors ( int n ) { int cnt = 0 ; for ( int i = 1 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) cnt ++ ; cnt = cnt + 2 ; } } return cnt ; } int main ( ) { printf ( " Total ▁ distinct ▁ divisors ▁ of ▁ 100 ▁ are ▁ : ▁ % d " , countDivisors ( 100 ) ) ; return 0 ; }