Ways to express a number as product of two different factors | CPP program to find number of ways in which number expressed as product of two different factors ; To count number of ways in which number expressed as product of two different numbers ; To store count of such pairs ; Counting number of pairs upto sqrt ( n ) - 1 ; To return count of pairs ; Driver program to test countWays ( )
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countWays ( int n ) { int count = 0 ; for ( int i = 1 ; i * i < n ; i ++ ) if ( n % i == 0 ) count ++ ; return count ; } int main ( ) { int n = 12 ; cout << countWays ( n ) << endl ; return 0 ; }