← Complete problem index

PROJECT EULER · #0795

Alternating GCD Sum

Statement only · SolvedOriginal problem ↗

For a positive integer n, the function g(n) is defined as

g(n)=∑i=1n(−1)igcd(n,i2).

For example, g(4)=−gcd(4,12)+gcd(4,22)−gcd(4,32)+gcd(4,42)=−1+4−1+4=6.
You are also given g(1234)=1233.

Let G(N)=∑n=1Ng(n). You are given G(1234)=2194708.

Find G(12345678).

Write-up coming later

The complete problem is available here. An approach, code, and answer will be added later.