Ways to express a number as product of two different factors
Given a number n, write a program to calculate the number of ways in which numbers can be expressed as the product of two different factors.
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 be expressed as the product of two factors we only need to find the number of factors of number up to the square root of the number. And we only need to find only different pairs so in the case of a perfect square we don’t include that factor.
Time Complexity: O(√n)
Auxiliary Space: O(1)
This article is contributed by Aarti_Rathi and nuclode. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to email@example.com. 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.