When writing a program it is a challenge to make a program reusable. The same can be done to solutions of exercises. You can try to generalise the solution. I generalized a result of a number theory problem I solved.

Let n be a positive integer and D the set of divisors of n. We are interested in the sum of all quotients a/b, where a,b in D and GCD(a,b)=1.

Example

n=5

D={1,5}

Quotients: {1/1, 5/1, 1/5}

Sum 6 1/5

n=12

D={1,2,3,4,6,12}

Quotients: {1/1, 2/1, 3/1, 4/1, 6/1, 12/1, 1/2, 3/2, 1/3, 2/3, 4/3, 1/4, 3/4, 1/6, 1/12}

Sum 33 7/12

Formula:

g[{x_,y_}]:=(1-x^(2y+1))/((1-x)*x^y)

f[n_]:=Apply[Times,Map[g,FactorInteger[n]]]

( In Mathematica format )

The function is Arithmetic, i.e. f[x]*f[y] = f[x*y] if GCD[x,y]=1.

Explanation.

If p is a prime then

f[p^n] = p^n + p^(n-1) + ... + 1 + 1/p + 1/p^2 + ... + 1/p^n

now use the fact that f is arithmetic and map the primefactorization of n to this function.

13-2016 Open letter to Open Source for You (OSFY)

5 months ago

## No comments:

## Post a Comment