1
$\begingroup$

I would like to calculate sum of $GCD(i, j)$ of all pairs $1 \le i \le n, 1 \le j \le m$, i.e. $\sum_{i=1}^n \sum_{j=1}^m GCD(i, j)$. Is there any faster method than calculating all those $n * m$ gcd's and summing them?

  • 0
    Yes, but they require that you know the prime factorisations of all numbers less than $m$ or $n$. And it's still kindof tricky.2017-01-31
  • 0
    Assuming that i can factorize them, how would i calculate this sum2017-01-31
  • 0
    For what it's worth, the case $m=n$ is tablated at http://oeis.org/A018806. Similar question, http://math.stackexchange.com/questions/1750854/how-to-calculate-double-sum-of-gcdi-j2017-02-05

1 Answers 1

0

If you have $O(n*m)$ memory, you can store prevous GCD values and calculate GCD with $O(1)$ complexity