Count of the non | C ++ program to find count of non - prime divisors of given number ; Function to factors of the given number ; Loop to find the divisors of the number 2 ; Loop to find the divisors of the given number upto SQRT ( N ) ; Condition to check if the rest number is also a prime number ; Function to find the non - prime divisors of the given number ; Loop to count the number of the total divisors of given number ; Driver Code ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; vector < int > getFactorization ( int x ) { int count = 0 ; vector < int > v ; while ( x % 2 == 0 ) { count ++ ; x = x / 2 ; } if ( count != 0 ) v . push_back ( count ) ; for ( int i = 3 ; i <= sqrt ( x ) ; i += 2 ) { count = 0 ; while ( x % i == 0 ) { count ++ ; x /= i ; } if ( count != 0 ) v . push_back ( count ) ; } if ( x > 1 ) { v . push_back ( 1 ) ; } return v ; } int nonPrimeDivisors ( int N ) { vector < int > v = getFactorization ( N ) ; int ret = 1 ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) ret = ret * ( v [ i ] + 1 ) ; ret = ret - v . size ( ) ; return ret ; } int main ( ) { int N = 8 ; cout << nonPrimeDivisors ( N ) << endl ; return 0 ; }