Click here to Skip to main content
15,888,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Task. Splits into different multipliers

This task is formulated very briefly.

Given a natural number N. you need to find the number of ways to represent it as a product of pairwise different factors greater than 1.

The format of the input data

The first line contains a single natural number 2 < = N < = 10^12 .

Output format

Output a single number - the number of ways to represent the number N as a product of pairwise different factors greater than 1.

Explanation for example. There are 7 different ways to represent the number 48 as a product (including a degenerate one) of pairwise different multipliers. 1: 48, 2 * 24, 3 * 16, 4 * 12, 6 *8, 2 * 3 * 8, 2 * 4 * 6.


What I have tried:

I was trying to write an algorithm and looking for a mathematical formula.
Posted
Updated 10-Oct-20 2:05am
v2
Comments
Greg Utas 9-Oct-20 18:37pm    
"Pairwise unequal"? So that rules out 2*2*12, for example?

I don't see why 2*6*4 and 4*6*2 should both be counted.

And what about 2*24?

You also said greater than 1, so 48(*1) shouldn't count.
temchik_ggg 10-Oct-20 5:20am    
Sorry I made a mistake, here is the corrected question.

Task. Splits into different multipliers

This task is formulated very briefly.

Given a natural number N. you need to find the number of ways to represent it as a product of pairwise different factors greater than 1.

The format of the input data

The first line contains a single natural number 2 < = N < = 10^12 .

Output format

Output a single number - the number of ways to represent the number N as a product of pairwise different factors greater than 1.

Explanation for example. There are 7 different ways to represent the number 48 as a product (including a degenerate one) of pairwise different multipliers. 1: 48, 2 * 24, 3 * 16, 4 * 12, 6 *8, 2 * 3 * 8, 2 * 4 * 6.
Richard MacCutchan 10-Oct-20 4:17am    
Start with the number divided by 2. That is the first (possible) factor. As Patrice suggest below, use the modulo function to see if that is a valid factor. Then do the same for every value below that on down to 2.

As Greg spotted in comment, your example makes no sense.

In matter of integer factorization, the operation is modulo.
Modulo gives the reminder of the integer division. When modulo is 0 you got a factor.
Modulo operation - Wikipedia[^]
 
Share this answer
 
Comments
CPallini 10-Oct-20 1:56am    
5.
Patrice T 10-Oct-20 1:59am    
Thank you
temchik_ggg 10-Oct-20 5:21am    
Sorry I made a mistake, here is the corrected question.

Task. Splits into different multipliers

This task is formulated very briefly.

Given a natural number N. you need to find the number of ways to represent it as a product of pairwise different factors greater than 1.

The format of the input data

The first line contains a single natural number 2 < = N < = 10^12 .

Output format

Output a single number - the number of ways to represent the number N as a product of pairwise different factors greater than 1.

Explanation for example. There are 7 different ways to represent the number 48 as a product (including a degenerate one) of pairwise different multipliers. 1: 48, 2 * 24, 3 * 16, 4 * 12, 6 *8, 2 * 3 * 8, 2 * 4 * 6.
Patrice T 10-Oct-20 5:42am    
Use Improve question to update your question.
So that everyone can pay attention to this information.
def algorithm(n, start=2):
    if n == 1:
        return 1
    else:
        ans = 0
        for i in range(start, n + 1):
            if n % i == 0:
                ans += algorithm(n // i, i + 1)
        return ans

num = int(input())
ans = algorithm(num)
print(ans)
 
Share this answer
 
Comments
Richard MacCutchan 10-Oct-20 8:11am    
Your start value should be n/2 which is the largest possible factor. And your loop should count from that value down to 2 which is the smallest.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900