How many 5 digit positive integers are there such that each of its digits, except for the last one, is greater than or equal to the next digit?
This problem is part of this set .
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.
1 2 3 4 5 6 7 8 9 10 11 |
|
But, when you run this code, you get 2001:
Dim counter As Integer = 0
For n = 10000 To 99999
Dim a As String = n.ToString
Dim a_char() = a.ToCharArray
If ((a(0) >= a(1)) And (a(1) >= a(2)) And (a(2) >= a(3)) And (a(3) >= a(4))) Then
counter = counter + 1
End If
Next
Console.WriteLine(counter)
Console.ReadLine()
I got 2002 :/. Is n = 10000 to 99999 inclusive?
I f y o u f o l l o w t h e p a t t e r n o f t h e w a y t h e s e n u m b e r s a r e f o r m e d , y o u c a n s e e s u c h a p a t t e r n f o r w h e n t h e d i g i t i i s a t t h e 1 0 , 0 0 0 ′ s p l a c e : I f k 1 ( i ) r e p r e s e n t s t h e n u m b e r o f n u m b e r s l i k e i i i i _ , i . e , t h e n u m b e r o f n u m b e r s w i t h i e v e r y w h e r e b u t t h e u n i t s p l a c e , t h e n k 1 ( i ) = i + 1 . F o l l o w i n g t h e w e i r d r e c u r s i v e p a t t e r n , k 1 0 ( i ) = ∑ 0 i k 1 ( r ) = ∑ 0 i ( r + 1 ) = 2 ( i + 1 ) ( i + 2 ) . H e r e , k 1 0 ( i ) r e p r e s e n t s t h e n u m b e r o f n u m b e r s l i k e i i i _ _ . S i m i l a r l y , k 1 0 0 ( i ) = ∑ 0 i 2 ( r + 1 ) ( r + 2 ) = ∑ 0 i k 1 0 ( r ) = 6 ( i + 1 ) ( i + 2 ) ( i + 3 ) . F o r t h e l a s t o n e , k 1 0 0 0 ( i ) , r e p r e s e n t i n g i _ _ _ _ , w e g e t t h e n u m b e r o f n u m b e r s s t a r t i n g w i t h d i g i t i a n d s u b j e c t t o g i v e n c o n d i t i o n s . k 1 0 0 0 ( i ) = ∑ 0 i k 1 0 0 ( r ) = 2 4 ( i + 1 ) ( i + 2 ) ( i + 3 ) ( i + 4 ) . N o w f o r t h e t o t a l n u m b e r o f s u c h n u m b e r s , N = ∑ 1 9 k 1 0 0 0 ( r ) = 2 0 0 1 . W h e n I e n t e r e d 2 0 0 1 , i t n a t u r a l l y s a i d w r o n g . I a s s u m e d t h a t t h e q u e s t i o n w a s s u p p o s e d t o i n c l u d e 0 0 0 0 0 . I e n t e r e d 2 0 0 2 a n d i t s a i d t h a t i t w a s c o r r e c t . I r e c h e c k e d i t w i t h a c o m p u t e r p r o g r a m a n d i t s a i d t h e s a m e t h i n g . I t h i n k t h a t t h e q u e s t i o n w a s m e a n t t o r e a d , ′ a l l n o n − n e g a t i v e i n t e g e r s ′ . I f 2 0 0 2 i s t h e r i g h t a n s w e r a n d a n y o n e h a s o b t a i n e d i t w i t h o u t i n c l u d i n g 0 0 0 0 0 , w h i c h i s n o t a p o s i t i v e i n t e g e r , p l e a s e l e t m e k n o w .
Solve it my way
Let it be a b c d e then 1 3 ≥ a + 4 > b + 3 > c + 2 > d + 1 > e ≥ 0 so it is equal to the ways to choose 5 different numbers out of 1 4 Hence answer is ( 5 1 4 ) = 2 0 0 2
Log in to reply
Thanks! Your method is much shorter than mine! Wish I had thought of that.
Log in to reply
Wait, I still have one doubt: you said that it's the same as choosing 5 nos out of 14 in the set {0,1,...,12,13}. So this choice: {0,1,2,3,4} would also be in it, right? That means a=b=c=d=e=0. So the number effectively formed = 00000 = 0 is not positive. Correct me if I'm wrong, but I still think that the question should be changed to non negative integers.
Thanks. In future, if you spot any errors with a problem, you can “report” it by selecting "report problem" in the “dot dot dot” menu in the lower right corner. This will notify the problem creator who can fix the issues.
Problem Loading...
Note Loading...
Set Loading...
Lets we assume that every digit from 0 to 9 is a, b, c, d, ... i. Then, we can form an equality a+b+c+d+e+f+g+h+i+j=5 (five is the total of its digits). This is a classic problem. We use the permutation there are 5 objects divide into 10 section that separated by 9 another objects. So it becomes 14!/9!5!. 14C5 is 2002. But there is one solution that isn't accepted when all of its digits are zero. So the answer is 2002-1=2001