Given a number N. The task is to find the smallest N digit ODD number.
Input: N = 1 Output: 1 Input: N = 3 Output: 101
Approach: There can be two cases depending on the value of N.
Case 1 : If N = 1 then answer will be 1.
Case 2 : If N != 1 then answer will be (10^(n-1)) + 1 because the series of the smallest odd numbers will go on like: 1, 11, 101, 1001, 10001, 100001, ….
Below is the implementation of the above approach:
# Python3 implementation of the approach
# Function to return smallest even
# number with n digits
def smallestOdd(n) :
if (n == 1):
return pow(10, n – 1) + 1
# Driver Code
n = 4
# This code is contributed by ihritik.
Time Complexity: O(1).
- Smallest Even number with N digits
- Smallest odd digits number not less than N
- Smallest even digits number not less than N
- Smallest number with sum of digits as N and divisible by 10^N
- Smallest number with at least n digits in factorial
- Find the smallest number whose digits multiply to a given number n
- Smallest number k such that the product of digits of k is equal to n
- Smallest number by rearranging digits of a given number
- Immediate smallest number after re-arranging the digits of a given number
- Smallest x such that 1*n, 2*n, ... x*n have all digits from 1 to 9
- Smallest multiple of N formed using the given set of digits
- Smallest multiple of 3 which consists of three given non-zero digits
- Smallest and Largest Palindrome with N Digits
- Lexicographically smallest permutation with no digits at Original Index
- Check whether product of digits at even places is divisible by sum of digits at odd place of a number
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 : ihritik