Do if you can

How many 3 digit numbers are there, whose sum of digits is not greater than 16 ?


The answer is 620.

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.

5 solutions

Melissa Quail
Feb 1, 2015

I used the generating functions method: The first digit can be any number between 1 and 9 inclusive, represented by the polynomial:

( x 1 + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 + x 8 + x 9 ) (x^1+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9) and the second and third digits can be between 0 and 9 inclusive, the choices for each digit represented by the polynomial:

( x 0 + x 1 + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 + x 8 + x 9 ) (x^0+x^1+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9)

So the generating function is:

( x 1 + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 + x 8 + x 9 ) ( x 0 + x 1 + x 2 + x 3 + x 4 + x 5 + x 6 + x 7 + x 8 + x 9 ) 2 ) (x^1+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9)(x^0+x^1+x^2+x^3+x^4+x^5+x^6+x^7+x^8+x^9)^2)

We are interested in the coefficients of the terms with a power of x that is no greater than 16 so we need to multiply out the brackets and find the coefficients (to multiply out the brackets you can use the multinomial theorem or just type it into wolfram alpha!). These coefficients(from x 16 x^{16} to x 1 x^1 ) are:

66, 69, 70, 69, 66, 61, 54, 45, 36, 28, 21, 15, 10, 6, 3 and 1

Adding these coefficients gives us the answer 620 \boxed{620} .

Trevor Arashiro
Jan 31, 2015

I would love to see an intuitive solution to this. I noticed that it had to do with the third diagonal of Pascal's triangle. The number of 3 digit numbers who's digit sum is no greater than n is sum of the triangular numbers up to n.

The general formula for even n LESS THAN 10 is

4 1 n 2 k 2 4 \displaystyle \sum_1^{\frac{n}{2}} k^2

For odd n LESS THAN 10

4 1 n 1 2 k 2 + n ( n + 1 ) 2 4\displaystyle \sum_1^{\frac{n-1}{2}} k^2+\dfrac{n(n+1)}{2}

When n is greater than 10 the pattern doesn't work since it would mean that a three digit could have one single digit as like a 10.

I don't know why it's like this however. I spent 5 minutes getting an answer and when I checked it, which took about an hour, I found this pattern.

I took the complement (it's symmetric) from 1 to 9 then brute force bashed 10 and 11, then subtracted that from 900.

Btw can someone verify that the answer isn't 618? Cuz that's what I had originally.

Trevor Arashiro - 6 years, 4 months ago

Log in to reply

The answer is confirmed to be 620, for verification run the Python solution I posted.

Brock Brown - 6 years, 4 months ago

Log in to reply

Thanks. Just wanted to verify that

Trevor Arashiro - 6 years, 4 months ago
Adhiraj Dutta
Apr 15, 2020

For lazy people -

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include<iostream>
int main ()
{ int k = 0;
for (int a=1; a < 10; ++a)
{
  { for (int b =0; b < 10; ++b)
     { for (int c = 0; c < 10; ++c)
              if ((a + b + c) < 17) 
                  { std::cout<<100*a + 10*b + c<<" ";
                     k++;}
}}}
std::cout<<"\n The number of such numbers = "<<k;
return 0;
}

Output -

1
2
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 180 181 182 183 184 185 186 187 190 191 192 193 194 195 196 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 270 271 272 273 274 275 276 277 280 281 282 283 284 285 286 290 291 292 293 294 295 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 360 361 362 363 364 365 366 367 370 371 372 373 374 375 376 380 381 382 383 384 385 390 391 392 393 394 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 450 451 452 453 454 455 456 457 460 461 462 463 464 465 466 470 471 472 473 474 475 480 481 482 483 484 490 491 492 493 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 540 541 542 543 544 545 546 547 550 551 552 553 554 555 556 560 561 562 563 564 565 570 571 572 573 574 580 581 582 583 590 591 592 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 630 631 632 633 634 635 636 637 640 641 642 643 644 645 646 650 651 652 653 654 655 660 661 662 663 664 670 671 672 673 680 681 682 690 691 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 720 721 722 723 724 725 726 727 730 731 732 733 734 735 736 740 741 742 743 744 745 750 751 752 753 754 760 761 762 763 770 771 772 780 781 790 800 801 802 803 804 805 806 807 808 810 811 812 813 814 815 816 817 820 821 822 823 824 825 826 830 831 832 833 834 835 840 841 842 843 844 850 851 852 853 860 861 862 870 871 880 900 901 902 903 904 905 906 907 910 911 912 913 914 915 916 920 921 922 923 924 925 930 931 932 933 934 940 941 942 943 950 951 952 960 961 970 
 The number of such numbers = 620

Ashu Gupta
Feb 2, 2015

https://www.youtube.com/watch?v=Z7QSzy6e-HA see this video for solution

Brock Brown
Jan 31, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def digit_sum(n):
    total = 0
    for digit in str(n):
        total += int(digit)
    return total
def goal(n):
    return digit_sum(n) <= 16
count = 0
for n in xrange(100,1000):
    if goal(n):
        count += 1
print "Answer:", count

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...