SHARE
TWEET

Untitled

a guest Jul 16th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. '''For Example, consider the given series: 1, 2, 1, 3, 2, 5, 3, 7, 5, 11, 8, 13, 13, 17, …
  2. This series is a mixture of 2 series – all the odd terms in this series form a Fibonacci series and
  3. all the even terms are the prime numbers in ascending order. Now write a program to find the Nth term in this series.'''
  4.  
  5. from math import sqrt
  6. def NthPrime(n) :
  7.     count = 0
  8.     MAX=1000
  9.     for i in range(2, MAX + 1) :
  10.         check = 0
  11.         for j in range(2, int(sqrt(i)) + 1) :
  12.             if i % j == 0 :
  13.                 check = 1
  14.                 break
  15.  
  16.         if check == 0 :
  17.             count += 1
  18.  
  19.         if count == n :
  20.             return i
  21.             break
  22.  
  23.  
  24. def fib(n):
  25.     if n==0:
  26.         return 0
  27.     elif n==1:
  28.         return 1
  29.     else:
  30.         return fib(n-1)+fib(n-2)
  31.  
  32.  
  33.  
  34. n=int(input())
  35. if(n%2==0):
  36.     print(NthPrime(n//2))
  37. else:
  38.     print(fib((n//2)+1))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top