#P14035. [PAIO 2025] GCD
[PAIO 2025] GCD
题目背景
DO NOT include gcd.h
. Submit using C++ >=17.
题目描述
You are given a sequence of integers . You are also given an integer and an integer .
Let denote the greatest common divisor of the integers . For example, , .
We define $f_{l,r}(x) = \text{gcd}(A[1], A[2], \dots, A[l], A[r+1], \dots, A[N])^K \oplus x$, where denotes the bitwise XOR operation. Your task is to calculate the sum:
$$\left(\sum_{x=0}^{V} \sum_{l=1}^{N} \sum_{r=l}^{N} f_{l,r}(x) \cdot (A[l] + A[r])\right) \bmod 998\,244\,353 $$Implementation Details
You need to implement one procedure called calculate_sum
:
int32 calculate_sum(int32 N, int32 K, int32 V, int32[] A);
- : the number of integers in the sequence;
- : the exponent;
- : the maximum value of ;
- : the sequence of integers;
- This procedure might be called no more than 100 times for each test case at the beginning of the program.
The procedure should return the sum modulo 998244353:
$$\left(\sum_{x=0}^{V} \sum_{l=1}^{N} \sum_{r=l}^{N} f_{l,r}(x) \cdot (A[l] + A[r])\right) \bmod 998\,244\,353 $$提示
Examples
Example 1
Consider the following call.
calculate_sum(3, 2, 3, [3, 6, 2]);
The procedure should return 132.
Example 2
Consider the following call.
calculate_sum(7, 1, 0, [1, 2, 3, 4, 5, 6, 7]);
The procedure should return 168.
Sample Grader
The sample grader reads the input in the following format:
- Line 1: Three integers and
- Line 2: integers
The sample grader calls calculate_sum(N, K, V, A)
and prints the returned value.
Constraints
- for each .
Scoring
- Subtask 1 (4 points):
- Subtask 2 (8 points):
- Subtask 3 (15 points):
- Subtask 4 (11 points):
- Subtask 5 (17 points):
- Subtask 6 (21 points):
- Subtask 7 (11 points):
- Subtask 8 (13 points): No additional constraints.