No.1019 Minimal Lattice Triangles
Problem Statement
A point on the coordinate plane whose $x,y$ coordinates are both integers is called a lattice point. The area of a triangle whose $3$ vertices are all lattice points is always at least $\frac12$. Hereafter, a triangle of area $\frac12$ consisting of lattice points is called a minimal lattice triangle.
Ushiko loves minimal lattice triangles. In particular, she feels great joy when she finds one with large coordinates. Let us calculate the total joy that Ushiko can obtain.
Given a positive integer $N$, calculate the following value.
- When the $3$ points $O(0,0), P(p_1,p_2), Q(q_1,q_2)$ form a minimal lattice triangle, its joy is defined as $|p_1| + |p_2| + |q_1| + |q_2|$.
- Find the sum of the joy over all minimal lattice triangles $OPQ$ satisfying $OP\leqq \sqrt{N}$ and $OQ\leqq \sqrt{N}$, modulo $998244353$.
Input
$N$
- $N$ is a positive integer satisfying $1\leqq N\leqq 10^{12}$.
Output
Output on $1$ line the sum of the joy modulo $998244353$.
Print a newline at the end.
Sample
Sample 1
Input
1
Output
8
For example, $P(1,0)$, $Q(0,1)$ gives a minimal lattice triangle. This triangle yields a joy of $2$. The $4$ triangles obtained by rotating this triangle about $O$ in steps of $90$ degrees are the ones to be counted.
Sample 2
Input
25
Output
1208
For example, $P(4,-3)$, $Q(-3,2)$ gives a minimal lattice triangle. This triangle yields a joy of $12$.
Sample 3
Input
1000000
Output
741919871
Output the value modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
maspy
beet