a × b + c = a + b × c
How many ordered triples ( a , b , c ) of integers with 0 ≤ a , b , c ≤ 1 0 are there such that the above statement is valid?
Solve this problem with a program.
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.
Simple standard approach of running through all possible cases.
There is still no change in efficiency here. As the code runs 1000 times.
Log in to reply
Yes. I have not made any modifications yet. I'll do it later.
Here is an algorithm as one of the approaches:
1 2 3 4 5 6 7 |
|
I expect even better approach.
Why coding when we can do this with elementary combinatorics?
a + b c = a b + c ⟺ ( b − 1 ) ( a − c ) = 0
Now, consider two cases: (i) when a = c and (ii) when a = c
For case ( i ) , the LHS is 0 regardless of what b is, so fixing a , c with the same value k (say) , we have 1 1 choices for b . Since there are also 1 1 choices for k , the total number of ordered pairs ( a , b , c ) ∈ Z 3 that satisfy the given condition is 1 1 2 = 1 2 1 .
For case ( i i ) , the LHS is 0 iff b = 1 . So, fixing b as 1 , we can take distinct a , c from 1 1 choices in 1 1 P 2 = 1 1 0 ways.
Obviously, cases ( i ) and ( i i ) are mutually exclusive and exhaustive, so the total number of ordered triplets ( a , b , c ) ∈ Z 3 that satisfy the problem conditions is 1 2 1 + 1 1 0 = 2 3 1 .
A more general result would be, if x ≤ a , b , c ≤ y where x , y ∈ Z , then the total number of ordered triples ( a , b , c ) ∈ Z 3 that satisfy the given condition is given by t ( 2 t − 1 ) where t = ∣ y − x + 1 ∣ .
You should easily be able to code this up in Python as follows:
1 2 3 |
|
Since
0
≤
a
,
b
,
c
≤
1
0
, calling
func(0,10)
will give you the required answer.
Log in to reply
Nice! Can you add the first part as a solution?
Nice! That's exactly what I expected. Thanks for your contribution. Moreover please upload the first part as solution.
Try to solve it manually:
a
b
+
c
=
a
+
b
c
(
b
−
1
)
(
a
−
c
)
=
0
b
=
1
or
a
=
c
By inclusion-exclusion principle, answer =
1
1
2
+
1
1
2
−
1
1
=
2
3
1
Problem Loading...
Note Loading...
Set Loading...
The answer can also be found out manually but here's the code -
It works because True is also considered as 1 in Python. A small modification can probably greatly speed up the process and allow multiple variables.