Approach:
Approach: Starting from 2, keep checking if the number is made up of only Prime digits (2,3,5,7) and stop when nth such number is found.
Below is the implementation of the above approach:
Python Code:
def isPrime(n):
def isPrime(n):
for num in range(2, int(n ** 0.5) + 1):
if n % num == 0:
return False
if n == 0 or n == 1:
return False
return True
def findNthprimeDigitNumber(n):
count = 0
i = 2
lst = []
while True:
num = i
k = str(num)
isMadeOfprime = True
while num >= 1:
if (isPrime(int(num % 10))) == 0:
isMadeOfprime = False
break
elif num < 2:
isMadeOfprime = False
break
num /= 10
if isMadeOfprime == True and isPrime(int(k[0])):
count += 1
lst.append(i)
if count == n:
# print(lst)
return i
i += 1
if __name__ == "__main__":
print(findNthprimeDigitNumber(int(input())))
0 Comments