{"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 Codeforces round. Its input format looks roughly as follows:\n\n_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**._\n\nIf 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.\n\nHere 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.\n\nConsider two wrong solutions to this problem which differ from the correct one only in the formula for calculating _x_.\n\nThe first wrong solution calculates _x_ as _x_ = _a__n_ / _g_ (without subtracting _n_).\n\nThe second wrong solution calculates _x_ as _x_ = _a__n_ - _n_ (without dividing by _g_).\n\nA test case is interesting if it makes **both** wrong solutions output an incorrect answer.\n\nGiven _max__n_, _max__a_ and _q_, find the number of interesting test cases satisfying the constraints, and output it modulo _q_.\n\n## Input\n\nThe 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).\n\n## Output\n\nOutput a single integer — the number of test cases which satisfy the constraints and make both wrong solutions output an incorrect answer, modulo _q_.\n\n[samples]\n\n## Note\n\nIn the first example, interesting test cases look as follows:\n\n1              1              1              3\n2              4              6              2 4 6","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] (#cf_span[1 ≤ ai ≤ maxa]) —— 集合的元素，按递增顺序排列。_\n\n如果你不关注问题的解法，似乎很容易为该问题生成一个良好的测试用例。令 #cf_span[n = maxn]，从 1 到 #cf_span[maxa] 中随机选取 #cf_span[n] 个互不相同的 #cf_span[ai]，然后排序……很快你就会发现这并不容易。\n\n以下是该问题的实际解法。令 #cf_span[g] 为 #cf_span[a1, a2, ..., an] 的最大公约数。令 #cf_span[x = an / g - n]。则正确解法在 #cf_span[x] 为奇数时输出 \"_Alice_\"，在 #cf_span[x] 为偶数时输出 \"_Bob_\"。\n\n考虑两个错误的解法，它们与正确解法的区别仅在于计算 #cf_span[x] 的公式。\n\n第一个错误解法计算 #cf_span[x] 为 #cf_span[x = an / g]（未减去 #cf_span[n]）。\n\n第二个错误解法计算 #cf_span[x] 为 #cf_span[x = an - n]（未除以 #cf_span[g]）。\n\n若一个测试用例使得 *两个* 错误解法均输出错误答案，则称其为“有趣的”。\n\n给定 #cf_span[maxn]、#cf_span[maxa] 和 #cf_span[q]，求满足约束条件的“有趣”测试用例的数量，并对 #cf_span[q] 取模输出。\n\n仅一行包含三个整数 #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])。\n\n输出一个整数 —— 满足约束条件且使两个错误解法均输出错误答案的测试用例数量，对 #cf_span[q] 取模。\n\n## Input\n\n仅一行包含三个整数 #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])。\n\n## Output\n\n输出一个整数 —— 满足约束条件且使两个错误解法均输出错误答案的测试用例数量，对 #cf_span[q] 取模。\n\n[samples]\n\n## Note\n\n在第一个例子中，有趣的测试用例如下：\n1              1              1              3\n2              4              6              2 4 6","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 = \\gcd(a_1, a_2, \\dots, a_n) $.  \nDefine:  \n- Correct $ x_c = \\frac{a_n}{g} - n $,  \n- Wrong1 $ x_1 = \\frac{a_n}{g} $,  \n- Wrong2 $ x_2 = a_n - n $.  \n\n**Constraints**  \n1. $ 1 \\leq n \\leq \\text{maxn} $  \n2. $ \\text{maxn} \\leq \\text{maxa} \\leq 10^9 $  \n3. $ a_i \\in \\mathbb{Z}^+ $, $ a_1 < a_2 < \\dots < a_n \\leq \\text{maxa} $  \n\n**Objective**  \nCount the number of sequences $ A $ such that:  \n- $ x_c $ is **odd** and $ x_1 $ is **even**, **or** $ x_c $ is **even** and $ x_1 $ is **odd**,  \n- **AND** $ x_c $ is **odd** and $ x_2 $ is **even**, **or** $ x_c $ is **even** and $ x_2 $ is **odd**.  \n\nEquivalently, count sequences where:  \n$$\nx_1 \\not\\equiv x_c \\pmod{2} \\quad \\text{and} \\quad x_2 \\not\\equiv x_c \\pmod{2}\n$$\n\nOutput the count modulo $ q $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF773F","tags":["combinatorics","divide and conquer","dp","fft","math","number theory"],"sample_group":[["3 6 100000","4"],["6 21 100129","154"],["58 787788 50216","46009"]],"created_at":"2026-03-03 11:00:39"}}