Skip to content

Commit

Permalink
Added Sylvester's Sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
PremApk committed Aug 2, 2021
1 parent 0e250ea commit 7673cad
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Sylvester Sequence/SylvesterSequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#########################
## Sylvester Sequence ##
#########################


#Example : 2 3 7 43 1807 3263443 ....

def seq(n):
pdt = 1
ans = 2
N = 1000000007
for i in range(1,n+1):
ans = ((pdt % N) * (ans % N)) % N
pdt = ans
ans = (ans + 1) % N
return ans

find_val = int(input("Enter the nth value to find : "))
print(find_val,"th value in Sylvester's Sequence is ",seq(find_val))

0 comments on commit 7673cad

Please sign in to comment.