#P7504. Coprime Summation Challenge
Coprime Summation Challenge
Coprime Summation Challenge
The adorable Theresa needs your help to compute the following expression:
$$ S = \sum_{x = 1}^n\sum_{y = 1}^n\Bigg(\Bigl[ x \bot k_1\Bigr]\sum_{i = 1}^x\Bigl([i\bot x]\cdot i\Bigr)\cdot \Bigl[ y \bot k_2\Bigr]\sum_{j = 1}^y\Bigl([j \bot y]\cdot j\Bigr)\Bigg) $$
Here, the notation is defined as follows:
$$ [a \bot b] = \begin{cases} 1 & \text{if } \gcd(a,b)=1, \\ 0 & \text{otherwise} \end{cases} $$
You are given three positive integers: n
, k1
, and k2
. You need to compute the sum S modulo 998244353.
Observe that the expression can be factored as follows:
$$ S = \Biggl(\sum_{x = 1}^n \Bigl[ x \bot k_1\Bigr] \cdot \left(\sum_{i = 1}^x [i\bot x] \cdot i\right)\Biggr) \times \Biggl(\sum_{y = 1}^n \Bigl[ y \bot k_2\Bigr] \cdot \left(\sum_{j = 1}^y [j\bot y] \cdot j\right)\Biggr) $$
Your task is to compute S mod 998244353
.
inputFormat
The input consists of a single line containing three space-separated integers n
, k1
, and k2
.
Constraints: You may assume that n
is small enough (for example, n ≤ 1000
) so that a simple solution works within the time limits.
outputFormat
Output a single integer: the value of S modulo 998244353.
sample
1 1 1
1