Problem Description Given two numbers n1 and n2 1. Find prime numbers between n1 and n2, then 2. Make all possible unique combinations of numbers from the prime numbers list you found in step 1. 3. From this new list, again find all prime numbers. 4. Find smallest (a) and largest (b) number from the 2nd generated list, also count of this list. 5. Consider smallest and largest number as the 1st and 2nd number to generate Fibonacci series respectively till the count (number of primes in the 2nd list). 6. Print the last number of a Fibonacci series as an output Constraints 2 <= n1, n2 <= 100 n2 - n1 >= 35 Input Format One line containing two space separated integers n1 and n2. Output Last number of a generated Fibonacci series.
Answers
Answer:
import math
import itertools
def check_prime(combinations):
prime_list2=[]
for num in combinations:
for i in range(2, math.floor(math.sqrt(num))+1):
if (num % i) == 0:
break
else:
prime_list2.append(num)
return list(set(prime_list2))
def find_prime_numbers(lower,upper):
prime_numbers=[]
for num in range(lower, upper + 1):
for i in range(2, math.floor(math.sqrt(num))+1):
if (num % i) == 0:
break
else:
prime_numbers.append(num)
return list(set(prime_numbers))
def get_combinations(prime_numbers):
combinations=[]
combo=set(itertools.permutations(prime_numbers,2))
for a,b in combo:
combinations.append(int("{}{}".format(a,b)))
return set(combinations)
def make_fibbonacci(no1,no2,count):
fib=[no1,no2]
for i in range(count-2):
fib.append(fib[i]+fib[i+1])
return fib[-1]
a,b=(int(i) for i in input().split())
if abs(a-b)>=35 and a>=1 and b<=100:
prime_numbers=find_prime_numbers(a,b)
combinations=get_combinations(prime_numbers)
prime_list2=check_prime(combinations)
print(make_fibbonacci(min(prime_list2),max(prime_list2),len(prime_list2)))
Explanation:
read it