user2891129
user2891129

Reputation:

LaTeX in Python

I need to implement this latex function in Python without using any external libraries:

R\left(A,\ B\right)=\sum_{n=1}^B\operatorname{mod}\left(A,n\right)

What is the most efficient way of going about this? BTW You can copy paste it into desmos.com in order to visualize it.

Upvotes: 0

Views: 171

Answers (1)

user3483203
user3483203

Reputation: 51165

If you just need to implement that function, you can use a list comprehension and sum():

def sum_mod(A, B):
  return sum(A % n for n in range(1, B+1))

print(sum_mod(7, 15))

Output:

64

Upvotes: 1

Related Questions