Given an integer N, the task is to find the count of natural octal numbers up to N digits.
Input: N = 1
1, 2, 3, 4, 5, 6, 7 are 1 digit Natural Octal numbers.
Input: N = 2
There are a total of 56 two digit octal numbers and 7 one digit octal numbers. Therefore, 56 + 7 = 63.
Approach: On observing carefully, a geometric progression series is formed [ 7 56 448 3584 28672 229376… ] with the first term being 7 and a common ratio of 8.
Nth term = Number of Octal numbers of N digits = 7 * 8N - 1
Finally, count of all octal numbers up to N digits can be found out by iterating a loop from 1 to N and calculating the sum of ith term using the above formula.
Below is the implementation of the above approach:
Time Complexity: O(N)
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of numbers upto N digits formed using digits 0 to K-1 without any adjacent 0s
- Count of numbers upto N having absolute difference of at most K between any two adjacent digits
- Count of numbers upto M divisible by given Prime Numbers
- Count numbers < = N whose difference with the count of primes upto them is > = K
- Count of numbers upto M with GCD equals to K when paired with M
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M
- Count numbers in given range such that sum of even digits is greater than sum of odd digits
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers
- Count numbers upto N which are both perfect square and perfect cube
- Count numbers with same first and last digits
- Count of numbers from range [L, R] that end with any of the given digits
- Count of numbers with all digits same in a given range
- Count of numbers from range [L, R] whose sum of digits is Y
- Count of Numbers in Range where the number does not contain more than K non zero digits
- Count different numbers that can be generated such that there digits sum is equal to 'n'
- Count numbers in range L-R that are divisible by all of its non-zero digits
- Count Numbers with N digits which consists of odd number of 0's
- Count the numbers with N digits and whose suffix is divisible by K
- Count of N-digit numbers with all distinct digits
- Count numbers formed by given two digit with sum having given digits
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : AnkitRai01