2

So currently I'm trying to solve this sum $$\sum_{i=1}^{2024} \gcd(i,8)$$

I decided to split it up into a couple of cases:

Case 1: $i$ is coprime to $8$

Well then $\gcd(i,8)=1$ for that $i$ correct? After some digging I find that there are $882$ numbers that are coprime to $8$ from $1 \leq i \leq2024$ using the technique in this post.

Now moving on I focused on the cases where $i$ is not coprime to $8$ . I noticed that there is a sort of cyclic pattern in the $\gcd(i,8)$. The pattern is like \begin{array}{|c|c|} \hline i & \gcd(i,8)\\\hline 2 & 2 \\ \hline 4 & 4 \\ \hline 6 & 2 \\ \hline 8 & 8 \\ \hline 10 & 2 \\ \hline 12 & 4 \\ \hline 14 & 2 \\ \hline 16 & 8 \\ \hline 18 & 2 \\ \hline ... & ... \\ \hline 2022 & 2 \\ \hline 2024 & 8 \\ \hline \end{array}

Case 2: when $i$ is such that $\gcd(i,8)=2$

Since there are $\lfloor \frac{2025}{2} \rfloor = 1012$ numbers that generate that thus the sum for those are $2(1012)=2024$.

Case 3: when $i$ is such that $\gcd(i,8)=4$

After some digging I found there are $253$ $i$'s that generate those, so the sum is $4(253)=1012$

Case 4: when $i$ is such that $\gcd(i,8)=8$

Again after some digging I found there are again $253$ $i$'s, so the sum will be $8(253)=2024$

Now I think I got all the cases, thus summing all of them up I got $882+2024+1012+2024=5942$. I'm confused since after looking at wolframalpha it seems the answer is $5060$, what was the thing I did that was false here? Can anyone point it out and correct it?

Blue
  • 83,939
JAB
  • 639

1 Answers1

4

I spotted two mistakes:

  • The number of $i\in\{1,\dots,2024\}$ that are relatively prime to $8$ is not $882$ but rather $1012$. Indeed, the integers relatively prime to $8$ are precisely the odd integers.
  • The number $\lfloor \frac{2024}2 \rfloor = 1012$ doesn't count numbers with $\gcd(i,8)=2$ but rather counts numbers divisible by $2$.

Here's another approach: note that the function $\gcd(i,8)$ is periodic with period $8$, repeating the pattern $1,2,1,4,1,2,1,8$ over and over. Therefore the sum can be broken up into $2024/8 = 253$ blocks of length $8$ each of which contributes an identical $1+2+1+4+1+2+1+8 = 20$ to the sum, and so the whole sum is $253\times20=5060$. (In a sense, your method was summing by “columns” first while this method is just summing by “rows” first; it just happens to be easier this way.)

Greg Martin
  • 92,241
  • Love your idea there! May I ask how you can prove the periodicity of $\gcd(i,8)$? How can I know for sure that it's value cycles through ${1,2,1,4,1,2,1,8}$? – JAB Sep 07 '24 at 07:32
  • The relevant lemma is that $\gcd(a,b)=\gcd(a,b+ka)$ for any integer $k$. This, by the way, is the crucial lemma for showing that the Euclidean algorithm does actually compute the greatest common divisor. – Greg Martin Sep 07 '24 at 17:23
  • 1
    Oh so this fact isn't only for $\gcd(i,8)$ but for others as well? – JAB Sep 08 '24 at 01:11