F. Test Data Generation

Codeforces
IDCF773F
Time5000ms
Memory256MB
Difficulty
combinatoricsdivide and conquerdpfftmathnumber theory
English · Original
Chinese · Translation
Formal · Original
Test data generation is not an easy task! Often, generating big random test cases is not enough to ensure thorough testing of solutions for correctness. For example, consider a problem from an old Codeforces round. Its input format looks roughly as follows: _The first line contains a single integer _n_ (1 ≤ _n_ ≤ _max__n_) — the size of the set. The second line contains _n_ distinct integers _a_1, _a_2, ..., _a__n_ (1 ≤ _a__i_ ≤ _max__a_) — the elements of the set **in increasing order**._ If you don't pay attention to the problem solution, it looks fairly easy to generate a good test case for this problem. Let _n_ = _max__n_, take random distinct _a__i_ from 1 to _max__a_, sort them... Soon you understand that it's not that easy. Here is the actual problem solution. Let _g_ be the greatest common divisor of _a_1, _a_2, ..., _a__n_. Let _x_ = _a__n_ / _g_ - _n_. Then the correct solution outputs "_Alice_" if _x_ is odd, and "_Bob_" if _x_ is even. Consider two wrong solutions to this problem which differ from the correct one only in the formula for calculating _x_. The first wrong solution calculates _x_ as _x_ = _a__n_ / _g_ (without subtracting _n_). The second wrong solution calculates _x_ as _x_ = _a__n_ - _n_ (without dividing by _g_). A test case is interesting if it makes **both** wrong solutions output an incorrect answer. Given _max__n_, _max__a_ and _q_, find the number of interesting test cases satisfying the constraints, and output it modulo _q_. ## Input The only line contains three integers _max__n_, _max__a_ and _q_ (1 ≤ _max__n_ ≤ 30 000; _max__n_ ≤ _max__a_ ≤ 109; 104 ≤ _q_ ≤ 105 + 129). ## Output Output a single integer — the number of test cases which satisfy the constraints and make both wrong solutions output an incorrect answer, modulo _q_. [samples] ## Note In the first example, interesting test cases look as follows: 1 1 1 3 2 4 6 2 4 6
生成测试数据并非易事!通常,仅生成大规模随机测试用例不足以确保对解决方案正确性的彻底检验。 例如,考虑来自一场旧 Codeforces 比赛的问题。其输入格式大致如下: _第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ maxn]) —— 集合的大小。第二行包含 #cf_span[n] 个互不相同的整数 #cf_span[a1, a2, ..., an] (#cf_span[1 ≤ ai ≤ maxa]) —— 集合的元素,按递增顺序排列。_ 如果你不关注问题的解法,似乎很容易为该问题生成一个良好的测试用例。令 #cf_span[n = maxn],从 1 到 #cf_span[maxa] 中随机选取 #cf_span[n] 个互不相同的 #cf_span[ai],然后排序……很快你就会发现这并不容易。 以下是该问题的实际解法。令 #cf_span[g] 为 #cf_span[a1, a2, ..., an] 的最大公约数。令 #cf_span[x = an / g - n]。则正确解法在 #cf_span[x] 为奇数时输出 "_Alice_",在 #cf_span[x] 为偶数时输出 "_Bob_"。 考虑两个错误的解法,它们与正确解法的区别仅在于计算 #cf_span[x] 的公式。 第一个错误解法计算 #cf_span[x] 为 #cf_span[x = an / g](未减去 #cf_span[n])。 第二个错误解法计算 #cf_span[x] 为 #cf_span[x = an - n](未除以 #cf_span[g])。 若一个测试用例使得 *两个* 错误解法均输出错误答案,则称其为“有趣的”。 给定 #cf_span[maxn]、#cf_span[maxa] 和 #cf_span[q],求满足约束条件的“有趣”测试用例的数量,并对 #cf_span[q] 取模输出。 仅一行包含三个整数 #cf_span[maxn]、#cf_span[maxa] 和 #cf_span[q] (#cf_span[1 ≤ maxn ≤ 30 000];#cf_span[maxn ≤ maxa ≤ 109];#cf_span[104 ≤ q ≤ 105 + 129])。 输出一个整数 —— 满足约束条件且使两个错误解法均输出错误答案的测试用例数量,对 #cf_span[q] 取模。 ## Input 仅一行包含三个整数 #cf_span[maxn]、#cf_span[maxa] 和 #cf_span[q] (#cf_span[1 ≤ maxn ≤ 30 000];#cf_span[maxn ≤ maxa ≤ 109];#cf_span[104 ≤ q ≤ 105 + 129])。 ## Output 输出一个整数 —— 满足约束条件且使两个错误解法均输出错误答案的测试用例数量,对 #cf_span[q] 取模。 [samples] ## Note 在第一个例子中,有趣的测试用例如下: 1 1 1 3 2 4 6 2 4 6
**Definitions** Let $ n \in \mathbb{Z} $, $ A = (a_1, a_2, \dots, a_n) $ be a strictly increasing sequence of positive integers with $ 1 \leq a_1 < a_2 < \dots < a_n \leq \text{maxa} $. Let $ g = \gcd(a_1, a_2, \dots, a_n) $. Define: - Correct $ x_c = \frac{a_n}{g} - n $, - Wrong1 $ x_1 = \frac{a_n}{g} $, - Wrong2 $ x_2 = a_n - n $. **Constraints** 1. $ 1 \leq n \leq \text{maxn} $ 2. $ \text{maxn} \leq \text{maxa} \leq 10^9 $ 3. $ a_i \in \mathbb{Z}^+ $, $ a_1 < a_2 < \dots < a_n \leq \text{maxa} $ **Objective** Count the number of sequences $ A $ such that: - $ x_c $ is **odd** and $ x_1 $ is **even**, **or** $ x_c $ is **even** and $ x_1 $ is **odd**, - **AND** $ x_c $ is **odd** and $ x_2 $ is **even**, **or** $ x_c $ is **even** and $ x_2 $ is **odd**. Equivalently, count sequences where: $$ x_1 \not\equiv x_c \pmod{2} \quad \text{and} \quad x_2 \not\equiv x_c \pmod{2} $$ Output the count modulo $ q $.
Samples
Input #1
3 6 100000
Output #1
4
Input #2
6 21 100129
Output #2
154
Input #3
58 787788 50216
Output #3
46009
API Response (JSON)
{
  "problem": {
    "name": "F. Test Data Generation",
    "description": {
      "content": "Test data generation is not an easy task! Often, generating big random test cases is not enough to ensure thorough testing of solutions for correctness. For example, consider a problem from an old Co",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 5000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF773F"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Test data generation is not an easy task! Often, generating big random test cases is not enough to ensure thorough testing of solutions for correctness.\n\nFor example, consider a problem from an old Co...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "生成测试数据并非易事!通常,仅生成大规模随机测试用例不足以确保对解决方案正确性的彻底检验。\n\n例如,考虑来自一场旧 Codeforces 比赛的问题。其输入格式大致如下:\n\n_第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ maxn]) —— 集合的大小。第二行包含 #cf_span[n] 个互不相同的整数 #cf_span[a1, a2, ..., an] (#c...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $, $ A = (a_1, a_2, \\dots, a_n) $ be a strictly increasing sequence of positive integers with $ 1 \\leq a_1 < a_2 < \\dots < a_n \\leq \\text{maxa} $.  \nLet $ g = ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments