Advertisement
gauravssnl

LargestPrimeWithUniqueDigit.py

Mar 14th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. def isprime(n ) :
  2.     for i in xrange( 2, n/2 +1  ) :
  3.         if n % i == 0 :
  4.             return False
  5.     return True
  6.  
  7. def isnumberunique( n ) :
  8.     s = str( n )
  9.    
  10.     for ch in set(s) :
  11.         if s.count(ch) > 1 :
  12.             return False
  13.     return True
  14.  
  15. num = pow( 10 ,9)
  16. naed = [0,2,4,5,6,8]
  17. naed =map(str,naed)
  18. while num :
  19.     while isnumberunique(num) is False and str(num)[-1] not in naed  :
  20.         num -= 1
  21.     if isprime( num):
  22.         print num
  23.         break
  24.     else :
  25.         num -= 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement