problem 586 // project euler



Binary Quadratic Form

The number 209 can be expressed as $a^2 + 3ab + b^2$ in two distinct ways:

$qquad 209 = 8^2 + 3cdot 8cdot 5 + 5^2$
$qquad 209 = 13^2 + 3cdot13cdot 1 + 1^2$

Let $f(n,r)$ be the number of integers $k$ not exceeding $n$ that can be expressed as $k=a^2 + 3ab + b^2$, with $agt b>0$ integers, in exactly $r$ different ways.

You are given that $f(10^5, 4) = 237$ and $f(10^8, 6) = 59517$.

Find $f(10^{15}, 40)$.


双重二次型

数209可以用两种方式表达为$a^2 + 3ab + b^2$:

$qquad 209 = 8^2 + 3cdot 8cdot 5 + 5^2$
$qquad 209 = 13^2 + 3cdot13cdot 1 + 1^2$

记$f(n,r)$为不超过$n$且恰好可以用$r$种方式表达为$k=a^2 + 3ab + b^2$的整数$k$的数目,其中整数$agt b>0$。

已知$f(10^5, 4) = 237$以及$f(10^8, 6) = 59517$。

求$f(10^{15}, 40)$。