Skip to content

Commit

Permalink
add Ramanujan sum
Browse files Browse the repository at this point in the history
  • Loading branch information
daedalus committed Nov 3, 2023
1 parent aa1b315 commit bb7e804
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ramanujan_sum.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Author Dario Clavijo 2023
# based on https://en.wikipedia.org/wiki/Ramanujan%27s_sum

from gmpy2 import *

ipi2 = (2j) * complex(gmpy2.const_pi())

def c(q,n):
sum_ = 0
nipi2 = ipi2 * n
for a in range(1, q+1):
if gcd(a,q) == 1:
sum_ += exp(nipi2 * (a/q))
return sum_

print([c(1,n).real for n in range(1, 31)])

0 comments on commit bb7e804

Please sign in to comment.