Menu Close

find-the-number-of-5-digit-natural-numbers-with-strictly-ascending-digits-whose-sum-is-20-example-12458-is-such-a-number-




Question Number 188362 by mr W last updated on 28/Feb/23
find the number of 5 digit natural  numbers with strictly ascending   digits whose sum is 20.  example: 12458 is such a number
findthenumberof5digitnaturalnumberswithstrictlyascendingdigitswhosesumis20.example:12458issuchanumber
Answered by ARUNG_Brandon_MBU last updated on 28/Feb/23
6
6
Commented by ARUNG_Brandon_MBU last updated on 28/Feb/23
#include <iostream> using namespace std; int main(void) { for (int i0, i1, i2, i3, i4, i=10000; i<100000; i++) { i0 = i/10000; i1 = i%10000/1000; i2 = i%1000/100; i3 = i%100/10; i4 = i%10; if (i0<i1 && i1<i2 && i2<i3 && i3<i4) if ((i0+i1+i2+i3+i4) == 20) cout << i <<", "; } return 0; }
Commented by ARUNG_Brandon_MBU last updated on 28/Feb/23
Output: 12359, 12368, 12458,                    12467, 13457, 23456,
Output:12359,12368,12458,12467,13457,23456,
Commented by mr W last updated on 28/Feb/23
yes!
yes!
Commented by ARUNG_Brandon_MBU last updated on 28/Feb/23
��
Commented by mr W last updated on 01/Mar/23
in this case, i mean when the sum of   digits is ≤20, we can still have a   smart solution, which gives us the  answer 7−1=6.  7 is the coef. of term x^(20)  in the  expansion Π_(k=1) ^5 (x^k /(1−x^k )). but it includes  also the case that a digit is 10, which  is certainly not true, therefore the  correct answer is 7−1=6.  if the sum of digits is >20, i think  we can only enumerate all possible  possibilities as your program does.  there is no smarter approach.
inthiscase,imeanwhenthesumofdigitsis20,wecanstillhaveasmartsolution,whichgivesustheanswer71=6.7isthecoef.oftermx20intheexpansion5k=1xk1xk.butitincludesalsothecasethatadigitis10,whichiscertainlynottrue,thereforethecorrectansweris71=6.ifthesumofdigitsis>20,ithinkwecanonlyenumerateallpossiblepossibilitiesasyourprogramdoes.thereisnosmarterapproach.
Commented by ARUNG_Brandon_MBU last updated on 28/Feb/23
����
Commented by mr W last updated on 04/Mar/23
i found a new way even for n>20,  see below. can you please check with  your program?
ifoundanewwayevenforn>20,seebelow.canyoupleasecheckwithyourprogram?
Commented by ARUNG_Brandon_MBU last updated on 07/Mar/23
// for n > 20 #include <iostream> using namespace std; int main(void) { for(int i0,i1,i2,i3,i4,i=10000;i<100000;i++) { i0 = i/10000; i1 = i%10000/1000; i2 = i%1000/100; i3 = i%100/10; i4 = i%10; if (i0<i1 && i1<i2 && i2<i3 && i3<i4) if (i0+i1+i2+i3+i4 > 20) cout << i <<" "; } return 0; }
Commented by ARUNG_Brandon_MBU last updated on 07/Mar/23
Commented by ARUNG_Brandon_MBU last updated on 07/Mar/23
We have 108 5-digit numbers such that  the digits are different and their sum > 20
Wehave1085digitnumberssuchthatthedigitsaredifferentandtheirsum>20
Commented by mr W last updated on 07/Mar/23
yes, that′s correct!  as we can see below there are  8 numbers with sum 21,  9 numbers with sum 22,  11 numbers with sum 23,  ...  2 numbers with sum 33,  1 number with sum 34,  1 number with sum 35.  so totally 108 numbers with sum>20.
yes,thatscorrect!aswecanseebelowthereare8numberswithsum21,9numberswithsum22,11numberswithsum23,2numberswithsum33,1numberwithsum34,1numberwithsum35.sototally108numberswithsum>20.
Answered by mr W last updated on 04/Mar/23
a new try  say the number is d_1 d_2 d_3 d_4 d_5  with  d_1 +d_2 +d_3 +d_4 +d_5 =n and  1≤d_1 <d_2 <d_3 <d_4 <d_5 ≤9  let   d_1 =1+k_1  with 0≤k_1 ≤8  d_2 =d_1 +1+k_2 =2+k_1 +k_2  with 0≤k_2 ≤7  d_3 =d_2 +1+k_3 =3+k_1 +k_2 +k_3  with 0≤k_3 ≤6  ......  d_5 =d_4 +1+k_4 =5+k_1 +k_2 +k_3 +...+k_5  with 0≤k_3 ≤4  (1+2+3+...+5)+5k_1 +4k_2 +3k_3 +2k_4 +k_5 =n  number of solutions is the coef. of  term x^n  in the expansion of  x^(15) Π_(r=1) ^5 ((1−x^(10−r) )/(1−x^r ))  for n=20 we have 6 numbers and  for n=25 we have 12 numbers etc.
anewtrysaythenumberisd1d2d3d4d5withd1+d2+d3+d4+d5=nand1d1<d2<d3<d4<d59letd1=1+k1with0k18d2=d1+1+k2=2+k1+k2with0k27d3=d2+1+k3=3+k1+k2+k3with0k36d5=d4+1+k4=5+k1+k2+k3++k5with0k34(1+2+3++5)+5k1+4k2+3k3+2k4+k5=nnumberofsolutionsisthecoef.oftermxnintheexpansionofx155r=11x10r1xrforn=20wehave6numbersandforn=25wehave12numbersetc.
Commented by mr W last updated on 04/Mar/23
Commented by mr W last updated on 04/Mar/23
in case of 6 digit numbers we need  to find the coef. of term x^n  in  x^(21) Π_(r=1) ^6 ((1−x^(10−r) )/(1−x^r ))  for n=25 we have 4 numbers and  for n=30 we have 8 numbers etc.
incaseof6digitnumbersweneedtofindthecoef.oftermxninx216r=11x10r1xrforn=25wehave4numbersandforn=30wehave8numbersetc.
Commented by mr W last updated on 04/Mar/23

Leave a Reply

Your email address will not be published. Required fields are marked *