Problem 341: Golomb's self-describing sequence

FCC link

The Golomb's self-describing sequence {G(n)} is the only nondecreasing sequence of natural numbers such that n appears exactly G(n) times in the sequence. The values of G(n) for the first few n are

n123456789101112131415…G(n)122334445556666…

You are given that G(103) = 86, G(106) = 6137. You are also given that ΣG(n3) = 153506976 for 1 ≤ n < 103.

Find ΣG(n3) for 1 ≤ n < 106.

Test

{{test}}

Console output