Computer Science, asked by bobburianusha7, 9 months ago

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. Timeout 1 Test Case Example 1 Input 2 40 Output 13158006689 Explanation 1st prime list = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37] Combination of all the primes = [23, 25, 27, 211, 213, 217, 219, 223, 229, 231, 32, 35, 37, 311, 313, 319, 323, 329, 331, 337, 52, 53, 57, 511, 513, 517, 519, 523, 529, 531, 537, 72, 73, 75, 711, 713, 717, 719, 723, 729, 731, 737, 112, 113, 115, 117, 1113, 1117, 1119, 1123, 1129, 1131, 1137, 132, 133, 135, 137, 1311, 1317, 1319, 1323, 1329, 1331, 1337, 172, 173, 175, 177, 1711, 1713, 1719, 1723, 1729, 1731, 1737, 192, 193, 195, 197, 1911, 1913, 1917, 1923, 1929, 1931, 1937, 232, 233, 235, 237, 2311, 2313, 2317, 2319, 2329, 2331, 2337, 292, 293, 295, 297, 2911, 2913, 2917, 2919, 2923, 2931, 2937, 312, 315, 317, 3111, 3113, 3. Try the suggestions below or type a new query above.

Answers

Answered by sarika170508
114

Answer:

I got this but still failing some test cases in Codevita.

Check this code out.

Explanation:

def test_prime(n):

   if (n==1):

       return False

   elif (n==2):

       return True;

   else:

       for x in range(2,n):

           if(n % x==0):

               return False

       return True

a,b=input().split(" ")

s=[]

r=[]

m=[]

for i in range(int(a),int(b)+1):

   if(test_prime(i)==True):

       s.append(i)

for i in range(len(s)):

   for j in range(len(s)):

       if(i!=j):

           r.append(int(str(s[i])+str(s[j])))

for i in range(len(r)):

   if(test_prime(int(r[i]))==True):

       if(r[i]  not in m):

           m.append(r[i])

m.sort()

a=m[0]

b=m[len(m)-1]

c=0

s.clear()

r.clear()

l=len(m)

l=l-2

while(l!=0):

   c=int(a)+int(b)

   a=b

   b=c

   s.append(c)

   l=l-1

m.clear()

print(s[len(s)-1])

s.clear()

Answered by pulkitmoolchandani
96

Answer:

import math

n1,n2=map(int,input().split())

l=[i for i in range(n2+1)]

l[1]=0

for i in range(2,n2+1):

 if(l[i] == i ):

   for j in range(2*i,n2+1,i):

     l[j]=0

k=[]

for i in l:

 if(i!=0 and i>=n1):

   k.append(i)

#print(k)

s=set()

for i in range(len(k)-1):

   for j in range(i+1,len(k)):

       s.add(int(str(k[i])+str(k[j])))

       s.add(int(str(k[j])+str(k[i])))

k=list(s)

k.sort()

#print(k)

minn=k[0]

maxx=k[-1]

m=[i for i in range(maxx+1)]

m[1]=0

for i in range(2,maxx+1):

 if(m[i] == i):

   for j in range(2*i,maxx+1,i):

     m[j]=0

prim2list=[]

for i in m:

   if(i >= minn and i in s):

       prim2list.append(i)

#print(prim2list)

minn=prim2list[0]

maxx=prim2list[-1]

lenn=len(prim2list)

#print(minn,maxx,lenn)

cnt=2

while(cnt<lenn):

   tmp=minn

   minn=maxx

   maxx=tmp+maxx

   cnt+=1

print(maxx)

   

Explanation:

ok

Similar questions