Practice Problem: Unit Sum
I know we haven't been doing much of these C++ Community problems so I though I'd write one up to get it started once again.
Problem Statement: For some integer v,w,x,y,z find all solution to the following equation
1 1 1 1 1
- + - + - + - + - = 1
v w x y z
For example one solution is v = w = x = y = z = 5, find the rest. If there are none the prove it with your code or some algebra. Happy coding fellas.
Related Article: C / C++ FAQ's and Practice problems
is a C++ discussion thread by ~s.o.s~ that has 26 replies, was last updated 6 months ago and has been tagged with the keywords: c++, faq, practice, problem, sticky.
firstPerson
Industrious Poster
4,044 posts since Dec 2008
Reputation Points: 851
Solved Threads: 625
Skill Endorsements: 15
There's nothing specifying that the numbers have to be positive. In that case, there are an infinite number of solutions, or since we're talking computer, "billyuns and billyuns" of them as our favorite astronomer used to say. v = w = x = 3. y and z and arithmetic inverses of each other (1, -1), (2, -2), (3, -3), etc so their reciprocals add to zero and they drop out. That's four billion right there. There are 5 choose 2 = 10 ways of picking which pair of variables are arithmetic inverses, so make it 40 billion and I'm just getting warmed up. Shall we change the problem to requiring the integers to all be positive?
VernonDozier
Posting Expert
5,675 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 738
Skill Endorsements: 18
I guess we also have to specify that the formula is not computed with integer arithmetic. Otherwise, for any integer greater than 1, the division would yield 0, and thus, there would be "billyuns and billyuns" of possibilities too (2^160 for 32bit unsigned integers). ;)
mike_2000_17
21st Century Viking
3,136 posts since Jul 2010
Reputation Points: 2,050
Solved Threads: 625
Skill Endorsements: 41
Omg nitpickers haha. Sorry should have been more precice.
- For all positive number
v,w,x,y,z - 1/a is not an integer division
firstPerson
Industrious Poster
4,044 posts since Dec 2008
Reputation Points: 851
Solved Threads: 625
Skill Endorsements: 15