problem Heegner

Among all non-square integers $n$ with absolute value not exceeding $10^3$ , find the value of $n$ such that $\cos(\pi\sqrt n)$ is closest to an integer.
在绝对值不超过 $10^3$ 的所有非平方数整数中,找到让 $\cos(\pi\sqrt n)$ 最接近整数的数.

题解(spoiler)

查阅资料:

直接带式子算就行.(真的吗?)
然后被炸 long double 精度,发现事情没有这么简单.
最后用python的mpmath库过去了,负数去exp大小能有e42这么大,普通python也会炸精度.

事实上查阅维基百科得知”黑格尔数”,页面有一个马尔努金常数,说e的多少次方pi非常接近整数,直接OSINT出来了,根本不用算.