You need to sign in or sign up before continuing.×
6 kyu

Sum and Product of Three Numbers

Description:

Problem

Given positive integers a and b, we want to write a function that calculates the number of possible sets (x, y, z) of positive integers `x ≤ y ≤ z such that:

x + y + z = a
x * y * z = b

Note that each set (x, y, z) is unique up to permutation. (E.g. if x = y, then (x, y, z) and (y, x, z) count as one and the same solution)

Examples

If a = 19 and b = 144, then the solutions are (2, 8, 9) and (3, 4, 12), because:

2 + 8 + 9 = 3 + 4 + 12 = 19
2 * 8 * 9 = 3 * 4 * 12 = 144

If a = 39 and b = 1200, then the solutions are (4, 15, 20), (5, 10, 24) and (6, 8, 25), because:

4 + 15 + 20 = 5 + 10 + 24 = 6 + 8 + 25 = 39
4 * 15 * 20 = 5 * 10 * 24 = 6 * 8 * 25 = 1200

Therefore, we want a function that:

number_of_sets(19, 144) = 2 #(2, 8, 9) and (3, 4, 12)
number_of_sets(39, 1200) = 3 #(4, 15, 20), (5, 10, 24) and (6, 8, 25)
Fundamentals

More By Author:

Check out these other kata created by CheeSenTan

Stats:

CreatedJan 27, 2021
PublishedJan 27, 2021
Warriors Trained434
Total Skips44
Total Code Submissions360
Total Times Completed133
Python Completions133
Total Stars9
% of votes with a positive feedback rating85% of 48
Total "Very Satisfied" Votes37
Total "Somewhat Satisfied" Votes8
Total "Not Satisfied" Votes3
Total Rank Assessments29
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • CheeSenTan Avatar
  • dfhwze Avatar
Ad