Operator Commutation

a × b + c = a + b × c a \times b + c = a + b \times c

How many ordered triples ( a , b , c ) (a,b,c) of integers with 0 a , b , c 10 0 \le a,b,c \le 10 are there such that the above statement is valid?

Solve this problem with a program.


Inspiration .


The answer is 231.

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.

3 solutions

Arulx Z
Jan 5, 2016

The answer can also be found out manually but here's the code -

1
sum(a * b + c == a + b * c for a in xrange(11) for b in xrange(11) for c in xrange(11))

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.

Moderator note:

Simple standard approach of running through all possible cases.

There is still no change in efficiency here. As the code runs 1000 times.

Zeeshan Ali - 5 years, 5 months ago

Log in to reply

Yes. I have not made any modifications yet. I'll do it later.

Arulx Z - 5 years, 5 months ago
Zeeshan Ali
Jan 5, 2016

Here is an algorithm as one of the approaches:

1
2
3
4
5
6
7
    count <- 0
    for a <- 0 to 10
        for b <- 0 to 10
            for b <- 0 to 10
                if a*b+c is a+b*c
                    count <- count+1
    return count

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 a+bc=ab+c\iff (b-1)(a-c)=0

Now, consider two cases: (i) when a = c a=c and (ii) when a c a\neq c

For case ( i ) (i) , the LHS is 0 0 regardless of what b b is, so fixing a , c a,c with the same value k (say) k\textrm{ (say)} , we have 11 11 choices for b b . Since there are also 11 11 choices for k k , the total number of ordered pairs ( a , b , c ) Z 3 (a,b,c)\in\Bbb{Z^3} that satisfy the given condition is 1 1 2 = 121 11^2=121 .

For case ( i i ) (ii) , the LHS is 0 0 iff b = 1 b=1 . So, fixing b b as 1 1 , we can take distinct a , c a,c from 11 11 choices in 11 P 2 = 110 ^{11}\mathbf{P}_2=110 ways.

Obviously, cases ( i ) (i) and ( i i ) (ii) are mutually exclusive and exhaustive, so the total number of ordered triplets ( a , b , c ) Z 3 (a,b,c)\in\Bbb{Z^3} that satisfy the problem conditions is 121 + 110 = 231 121+110=231 .


A more general result would be, if x a , b , c y x\leq a,b,c\leq y where x , y Z x,y\in\Bbb Z , then the total number of ordered triples ( a , b , c ) Z 3 (a,b,c)\in\Bbb{Z^3} that satisfy the given condition is given by t ( 2 t 1 ) t(2t-1) where t = y x + 1 t=|y-x+1| .


You should easily be able to code this up in Python as follows:

1
2
3
def func(x,y):
    t=abs(y-x+1)
    return t*(2*t-1)

Since 0 a , b , c 10 0\leq a,b,c\leq 10 , calling func(0,10) will give you the required answer.

Prasun Biswas - 5 years, 5 months ago

Log in to reply

Nice! Can you add the first part as a solution?

Calvin Lin Staff - 5 years, 5 months ago

Nice! That's exactly what I expected. Thanks for your contribution. Moreover please upload the first part as solution.

Zeeshan Ali - 5 years, 5 months ago
展豪 張
Mar 24, 2016

Try to solve it manually:
a b + c = a + b c ab+c=a+bc
( b 1 ) ( a c ) = 0 (b-1)(a-c)=0
b = 1 b=1 or a = c a=c
By inclusion-exclusion principle, answer = 1 1 2 + 1 1 2 11 = 231 11^2+11^2-11=231



0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...