fork download
  1. from itertools import permutations
  2. import sys
  3.  
  4. def isPrime(n):
  5. if n==1: return False
  6. if n==2 or n==3: return True
  7. if n%2==0 or n%3==0: return False
  8. i = 5
  9. while(i*i<=n):
  10. if n%i==0 or n%(i+2)==0: return False
  11. i += 6
  12. return True
  13.  
  14. def genFibNum(a,b,count):
  15. f1,f2 = a,b
  16. f3 = a+b
  17. i = 3
  18. while i<count:
  19. f1,f2 = f2,f3
  20. f3 = f1+f2
  21. i += 1
  22. return f3
  23.  
  24. if __name__ == "__main__":
  25. #step 1
  26. n1,n2 = list(map(int, sys.stdin.readline().split()))
  27. str_lst = list(map(str,[x for x in range(n1,n2) if isPrime(x)]))
  28.  
  29. #step 2
  30. comb_lst = list(set(map(lambda x: int("".join(x)),permutations(str_lst,2))))
  31.  
  32. #step 3
  33. second_lst = [x for x in comb_lst if isPrime(x)]
  34.  
  35. #step 4
  36. a, b = min(second_lst), max(second_lst)
  37. count = len(second_lst)
  38.  
  39. #step 5 n 6
  40. fibNum = genFibNum(a,b,count)
  41. print(fibNum)
Success #stdin #stdout 0.02s 9308KB
stdin
2 40
stdout
13158006689