#P11129. 【MX-X5-T1】「GFOI Round 1」Inverted World

【MX-X5-T1】「GFOI Round 1」Inverted World

Background

Original link: https://oier.team/problems/X5B


Inverted World - ARForest

Problem Description

Given a positive integer sequence (a1,,an)(a_1, \ldots, a_n) of length nn, it is guaranteed that this sequence is an arithmetic progression
(If you do not know the definition of an arithmetic progression, please refer to the hint at the end of the statement.)

Please find the number of non-empty contiguous subarrays (al,,ar)(a_l, \ldots, a_r) (1lrn1 \le l \le r \le n) in this sequence that satisfy:

  • The average of the elements in the subarray is an integer。
    (That is, (al++ar)÷(rl+1)(a_l + \cdots + a_r) \div (r - l + 1) is an integer.)

The sequence may be very long, i.e., nn can be very large, so the full sequence will not be given. Instead, only the length nn, the first term kk, and the common difference dd are given. It is guaranteed that k,d\bm{k, d} are both positive integers

Input Format

This problem contains multiple test cases。

The first line contains a positive integer TT, representing the number of test cases。

For each test case:

The first line contains three positive integers n,k,dn, k, d

Output Format

For each test case, output one line containing a non-negative integer, representing the number of subarrays whose average is an integer。

3
2 1 2
3 2 5
11451 41 91981
3
4
32787076

Hint

[Sample Explanation]

In the first test case, a=[1,3]a = [1, 3]。There are 33 non-empty contiguous subarrays that satisfy the requirement:

  • [1][1], whose average is 11
  • [3][3], whose average is 33
  • [1,3][1, 3], whose average is 22

In the second test case, a=[2,7,12]a = [2, 7, 12]。There are 44 non-empty contiguous subarrays that satisfy the requirement:

  • [2][2], whose average is 22
  • [7][7], whose average is 77
  • [12][12], whose average is 1212
  • [2,7,12][2, 7, 12], whose average is 77

[Constraints]

Test Point ID nn \le kk \le dd \le Score
11 1010 2828
22 10910^9 11 3535
33 10910^9 3737

For all testdata, it holds that 1T1031 \le T \le 10^3, 1n,k,d1091 \le n, k, d \le 10^9

[Definition Hint]

An arithmetic progression of length nn with first term kk and common difference dd is defined as a1=ka_1 = k and ai=ai1+da_i = a_{i - 1} + d (for every 2in2 \le i \le n)。

Translated by ChatGPT 5