![]() |
We are given a number N. The task is to find the count of numbers which have N digits and odd number of zeroes.
Examples: Input : N = 2 Output : Count = 18 Input : N = 3 Output : Count = 244 Suppose a number with N digits which contains only single zero. So the digits in the number as zero can be filled in only 1 way and the rest of each of the positions can be filled in 9 different ways with numbers from 1 to 9. So count of all such numbers with N digits and only 1 zero = NC1*(9N-1). Similarly, count of all such numbers with N digits and 3 zeroes = NC3*(9N-3). So, count of all such numbers with N digits and odd number of zeroes will be,
The above equation can be written as,
The above equation can be represented as subtraction of two series, (9N)*{(1+x)N-(1-x)N}/2, where x = 1/9 (10N - 8N)/2 Below is the implementation of the above approach: C++
Javascript
Output
33616 Note: Answer can be very large, so for N greater than 9, use modular exponentiation.
|
Reffered: https://www.geeksforgeeks.org
C++ Programs |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 7 |