Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- # Sieve Prime Finding BoilerPlate [20]
- def sivePrimes(n):
- prime = [True for i in range(n + 1)]
- p = 2
- while (p * p <= n):
- if (prime[p] == True):
- for i in range(p * 2, n + 1, p):
- prime[i] = False
- p += 1
- prime[0]= False
- prime[1]= False
- primes = []
- for p in range(n + 1):
- if prime[p]:
- primes.append(p)
- return primes
- # Get Inputs
- a,b = list(map(int,input().split()))
- sTime = time.time()
- # Find Primes Between List
- primes = sivePrimes(b)
- for x in primes:
- if x < a:
- continue
- else:
- index = primes.index(x)
- primes = primes[index:len(primes)]
- break
- # Creating Premutations
- from itertools import permutations
- PrimePermutaions = permutations(primes,2)
- PermutedPrimes = []
- for x in PrimePermutaions:
- number = int(str(x[0]) + str(x[1]))
- if not(number in PermutedPrimes):
- PermutedPrimes.append(number)
- PermutedPrimes = set(PermutedPrimes)
- a,b = min(PermutedPrimes),max(PermutedPrimes)
- primes = set(sivePrimes(b))
- # Find Primes in permuted primes
- commonPrimes = primes.intersection(PermutedPrimes)
- a,b = min(commonPrimes),max(commonPrimes)
- # Create Fib Serues
- FibArray = [a,b]
- def fibonacci(n):
- if n<0:
- print("Incorrect input")
- elif n<=len(FibArray):
- return FibArray[n-1]
- else:
- temp_fib = fibonacci(n-1)+fibonacci(n-2)
- FibArray.append(temp_fib)
- return temp_fib
- print(fibonacci(len(commonPrimes)))
- print("Time Taken : ",time.time() - sTime)
Add Comment
Please, Sign In to add comment