Problem 1909. Two fractions, one sum
Given a positive number x, write a MATLAB script that will tell you how many ways that the reciprocal of that number can be written as a sum of two reciprocals of integers. For example, 1/10 can be written as:
- 1/11 + 1/110
- 1/12 + 1/60
- 1/14 + 1/35
- 1/15 + 1/30
- 1/20 + 1/20
The order of the fractions does not matter, so 1/11+1/110 is the same as 1/110+1/11. Therefore, two_fractions(10)=5. You do not need to output the fraction pairs themselves, only the total number of sums. Good luck!
Solution Stats
Problem Comments
-
5 Comments
Although people have solved this already. I'm sure that there's an error in the 7th test suite.
two_fractions(10^7) = 113;
two_fractions(10^8) = 165;
two_fractions(two_fractions(10^7) + two_fractions(10^8)) ==> two_fractions(278) = 5 ==> not 14
Nick, I see where your problem is: two_fractions(10^8) is not 165. You are running into rounding errors on some of your larger fractions.
Ok Thanks. I'll have a look.
http://www.wolframalpha.com/input/?i=%28x%2By%29*5+%3D+x*y
Nice problem!
Solution Comments
Show commentsProblem Recent Solvers27
Suggested Problems
-
4179 Solvers
-
Recurring Cycle Length (Inspired by Project Euler Problem 26)
161 Solvers
-
429 Solvers
-
Generate a vector like 1,2,2,3,3,3,4,4,4,4
13535 Solvers
-
Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
896 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!