Given **a **and **b **which represents the location of two factors of N whose product is equal to the number N when the factors are arranged in ascending order. The task is to find the total number of factors of N.

**Examples:**

Input :a = 2, b = 3

Output :4

N = 6

factors are {1, 2, 3, 6}

No of factors are 4

Input :a = 13, b = 36

Output :48

**Approach : ** The solution is based on observation.

*Assume N = 50*. Then N has 6 factors 1, 2, 5, 10, 25 and 50. On multiplying 1 and 50 will always give the value 50( N ). Also, by multiplying 2 and 25 gives us the value N, similarly by multiplying 5 and 10 we get the value N. So, here we can see that by multiplying two factors when arranged in an increasing order gives the value N. The multiplication must be done in a manner: 1st factor and the last factor on multiplication gives N, 2nd factor and 2nd last factor on multiplication gives N and so on.

With this pattern, we can find a way to calculate the number of factors. Say, the 1st and 4th factor on multiplication gives N. This means that there are 4 factors ( 1st, 2nd, 3rd, and 4th ). If the product of 2nd and 3rd factor gives N then we can say there must be a factor in the 1st position and on the 4th position.

Therefore, the number of factors will be equal to **a + b – 1**.

Below is the implementation of the above approach:

## C++

`// C++ program to implement ` `// the above problem ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to find the number of factors ` `void` `findFactors(` `int` `a, ` `int` `b) ` `{ ` ` ` `int` `c; ` ` ` `c = a + b - 1; ` ` ` ` ` `// print the number of factors ` ` ` `cout << c; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `// initialize the factors position ` ` ` `int` `a, b; ` ` ` `a = 13; ` ` ` `b = 36; ` ` ` ` ` `findFactors(a, b); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java program to implement ` `// the above problem ` `class` `GFG ` `{ ` ` ` `// Function to find the number of factors ` `static` `void` `findFactors(` `int` `a, ` `int` `b) ` `{ ` ` ` `int` `c; ` ` ` `c = a + b - ` `1` `; ` ` ` ` ` `// print the number of factors ` ` ` `System.out.print(c); ` `} ` ` ` `// Driver code ` `public` `static` `void` `main(String[] args) ` `{ ` ` ` `// initialize the factors position ` ` ` `int` `a, b; ` ` ` `a = ` `13` `; ` ` ` `b = ` `36` `; ` ` ` ` ` `findFactors(a, b); ` `} ` `} ` ` ` `// This code is contributed by Princi Singh ` |

*chevron_right*

*filter_none*

## Python3

`# Python 3 program to implement ` `# the above problem ` ` ` `# Function to find the number of factors ` `def` `findFactors(a, b): ` ` ` `c ` `=` `a ` `+` `b ` `-` `1` ` ` ` ` `# print the number of factors ` ` ` `print` `(c) ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `'__main__'` `: ` ` ` ` ` `# initialize the factors position ` ` ` `a ` `=` `13` ` ` `b ` `=` `36` ` ` `findFactors(a, b) ` ` ` `# This code is contributed by ` `# Surendra_Gangwar ` |

*chevron_right*

*filter_none*

## C#

`// C# program to implement ` `// the above problem ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` `// Function to find the number of factors ` `static` `void` `findFactors(` `int` `a, ` `int` `b) ` `{ ` ` ` `int` `c; ` ` ` `c = a + b - 1; ` ` ` ` ` `// print the number of factors ` ` ` `Console.Write(c); ` `} ` ` ` `// Driver code ` `public` `static` `void` `Main(String[] args) ` `{ ` ` ` `// initialize the factors position ` ` ` `int` `a, b; ` ` ` `a = 13; ` ` ` `b = 36; ` ` ` ` ` `findFactors(a, b); ` `} ` `} ` ` ` `// This code is contributed by PrinciRaj1992 ` |

*chevron_right*

*filter_none*

**Output:**

48

** Time Complexity : ** O(1)

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:

- Product of divisors of a number from a given list of its prime factors
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Find the row whose product has maximum count of prime factors
- Count of nodes in a Binary Tree whose child is its prime factors
- Maximum number of prime factors a number can have with exactly x factors
- Ways to express a number as product of two different factors
- Find sum of product of every number and its frequency in given range
- Check if a number exists having exactly N factors and K prime factors
- Find N numbers such that a number and its reverse are divisible by sum of its digits
- Find a Number X whose sum with its digits is equal to N
- Find prime factors of Array elements whose sum of exponents is divisible by K
- Find four factors of N with maximum product and sum equal to N | Set-2
- Find four factors of N with maximum product and sum equal to N
- Find four factors of N with maximum product and sum equal to N | Set 3
- Find product of all elements at indexes which are factors of M for all possible sorted subsequences of length M
- Minimize the cost of selecting two numbers whose product is X
- Count of subsequences whose product is a difference of square of two integers
- Product of factors of number
- Product of unique prime factors of a number
- Maximize the product of four factors of a Number

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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.