count of 4 digits number with odd digits with sum 16

127 Views Asked by At

Let $abcd$ be a 4 digit number and $a,b,c,d$ are all odd digits (1,3,5,7,9). We want to find count of such numbers that $a+b+c+d =16$.

In the book in which I found this question, the answers was:

$a+b+c+d =16 \rightarrow (2x+1)+(2y+1)+(2z+1)+(2w+1) = 16 ;x,y,z,w\geq 0 \rightarrow x+y+z+w = 6 \rightarrow $

Answer = $6+4-1\choose 3$ $=84$

But I solved this with considering different situations for sum of (a+b) and (c+d) and get the answer 68. I also solved this via programming with c++ and get the answer 68. So I think the book is wrong but why the answer of the book is wrong?

C++ code:

#include <iostream>

using namespace std;

int main(int argc, char** argv) {

int c =0;

for (int i = 0;i<=9 ; i++)

{

for (int j = 0;j<=9 ; j++)

{

for (int k = 0;k<=9 ; k++)

{

for (int l = 0;l<=9 ; l++)


{

    if (i+j+k+l ==16 && i%2 ==1 && j%2 == 1 && k%2==1 && l % 2 ==1)

    {

        c++;

    }

}   

}   

}   



}

    cout<<c;

    return 0;

}
1

There are 1 best solutions below

1
On BEST ANSWER

The book is incorrect. The book counts the number of solutions for the following problem:

$$x,y,z,w\geq 0 \quad\wedge\quad x+y+z+w = 6$$

But this is not the same problem! $(x, y,z,w) = (0,0,0,6)$ is a solution, but this would give 'digit' $d = 2\cdot 6 + 1 = 13$.