Given a number n, write a program to calculate number of ways in which number can be expressed as product of two different factors.

**Examples :**

Input : 12 Output : 3 12 can be expressed as 1 * 12, 2 * 6 and 3*4. Input : 36 Output : 4 36 can be expressed as 1 * 36, 2 * 18, 3 * 12 and 4 * 9.

All factors of 12 are = 1, 2, 3, 4, 6, 12 We can observe that factors always exist in pair which is equal to number. Here (1, 12), (2, 6) and (3, 4) are such pairs.

As a number can expressed as product of two factors we only need to find number of factors of number upto square root of number. And we only need to find only different pairs so in case of perfect square we don’t include that factor.

## C++

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

*chevron_right*

*filter_none*

## Java

`// Java program to find number of ways ` `// in which number expressed as ` `// product of two different factors ` `public` `class` `Main { ` ` ` ` ` `// To count number of ways in which ` ` ` `// number expressed as product ` ` ` `// of two different numbers ` ` ` `static` `int` `countWays(` `int` `n) ` ` ` `{ ` ` ` `// To store count of such pairs ` ` ` `int` `count = ` `0` `; ` ` ` ` ` `// Counting number of pairs ` ` ` `// upto sqrt(n) - 1 ` ` ` `for` `(` `int` `i = ` `1` `; i * i < n; i++) ` ` ` `if` `(n % i == ` `0` `) ` ` ` `count++; ` ` ` ` ` `// To return count of pairs ` ` ` `return` `count; ` ` ` `} ` ` ` ` ` `// Driver program to test countWays() ` ` ` `public` `static` `void` `main(String[] args) ` ` ` `{ ` ` ` `int` `n = ` `12` `; ` ` ` `System.out.println(countWays(n)); ` ` ` `} ` `} ` |

*chevron_right*

*filter_none*

## Python 3

`# Python 3 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 ` `def` `countWays(n): ` ` ` ` ` `# To store count of such pairs ` ` ` `count ` `=` `0` ` ` `i ` `=` `1` ` ` ` ` `# Counting number of pairs ` ` ` `# upto sqrt(n) - 1 ` ` ` `while` `((i ` `*` `i)<n) : ` ` ` `if` `(n ` `%` `i ` `=` `=` `0` `): ` ` ` `count ` `+` `=` `1` ` ` `i ` `+` `=` `1` ` ` ` ` `# To return count of pairs ` ` ` `return` `count ` ` ` `# Driver program to test countWays() ` `n ` `=` `12` `print` `(countWays(n)) ` ` ` `# This code is contributed ` `# by Azkia Anam. ` |

*chevron_right*

*filter_none*

## C#

`// C# program to find number of ways ` `// in which number expressed as ` `// product of two different factors ` `using` `System; ` ` ` `public` `class` `main { ` ` ` ` ` `// To count number of ways in which ` ` ` `// number expressed as product ` ` ` `// of two different numbers ` ` ` `static` `int` `countWays(` `int` `n) ` ` ` `{ ` ` ` ` ` `// To store count of such pairs ` ` ` `int` `count = 0; ` ` ` ` ` `// Counting number of pairs ` ` ` `// upto sqrt(n) - 1 ` ` ` `for` `(` `int` `i = 1; i * i < n; i++) ` ` ` `if` `(n % i == 0) ` ` ` `count++; ` ` ` ` ` `// To return count of pairs ` ` ` `return` `count; ` ` ` `} ` ` ` ` ` `// Driver program to test countWays() ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `n = 12; ` ` ` ` ` `Console.WriteLine(countWays(n)); ` ` ` `} ` `} ` ` ` `// This code is contributed by Anant Agarwal. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP 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 ` `function` `countWays(` `$n` `) ` `{ ` ` ` `// To store count of such pairs ` ` ` `$count` `= 0; ` ` ` ` ` `// Counting number of pairs ` ` ` `// upto sqrt(n) - 1 ` ` ` `for` `(` `$i` `= 1; ` `$i` `* ` `$i` `< ` `$n` `; ` `$i` `++) ` ` ` `if` `(` `$n` `% ` `$i` `== 0) ` ` ` `$count` `++; ` ` ` ` ` `// To return count of pairs ` ` ` `return` `$count` `; ` `} ` ` ` `// Driver Code ` `$n` `= 12; ` `echo` `countWays(` `$n` `), ` `"\n"` `; ` ` ` `// This code is contributed by ajit ` `?> ` |

*chevron_right*

*filter_none*

**Output :**

3

This article is contributed by **nuclode**. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.

## Recommended Posts:

- Find number of factors of N when location of its two factors whose product is N is given
- Maximum number of prime factors a number can have with exactly x factors
- Count ways to express a number as sum of exactly two numbers
- Check if a number exists having exactly N factors and K prime factors
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Ways of dividing a group into two halves such that two elements are in different groups
- Count ways to split N! into two distinct co-prime factors
- Count ways to express a number as sum of consecutive numbers
- Count ways to express even number ānā as sum of even integers
- Product of factors of number
- Product of unique prime factors of a number
- Maximize the product of four factors of a Number
- Number less than equals to N with maximum product of prime factors
- Product of divisors of a number from a given list of its prime factors
- 8 different ways to Add Two Numbers in C/C++
- Print all combinations of factors (Ways to factorize)
- Find pairs of elements from two different arrays whose product is a perfect square
- Find four factors of N with maximum product and sum equal to N | Set-2
- Distinct Prime Factors of Array Product
- Find four factors of N with maximum product and sum equal to N