Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''For Example, consider the given series: 1, 2, 1, 3, 2, 5, 3, 7, 5, 11, 8, 13, 13, 17, …
- This series is a mixture of 2 series – all the odd terms in this series form a Fibonacci series and
- all the even terms are the prime numbers in ascending order. Now write a program to find the Nth term in this series.'''
- from math import sqrt
- def NthPrime(n) :
- count = 0
- MAX=1000
- for i in range(2, MAX + 1) :
- check = 0
- for j in range(2, int(sqrt(i)) + 1) :
- if i % j == 0 :
- check = 1
- break
- if check == 0 :
- count += 1
- if count == n :
- return i
- break
- def fib(n):
- if n==0:
- return 0
- elif n==1:
- return 1
- else:
- return fib(n-1)+fib(n-2)
- n=int(input())
- if(n%2==0):
- print(NthPrime(n//2))
- else:
- print(fib((n//2)+1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement