CF1848E.Vika and Stone Skipping

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In Vika's hometown, Vladivostok, there is a beautiful sea.

Often you can see kids skimming stones. This is the process of throwing a stone into the sea at a small angle, causing it to fly far and bounce several times off the water surface.

Vika has skimmed stones many times and knows that if you throw a stone from the shore perpendicular to the coastline with a force of ff, it will first touch the water at a distance of ff from the shore, then bounce off and touch the water again at a distance of f−1f - 1 from the previous point of contact. The stone will continue to fly in a straight line, reducing the distances between the points where it touches the water, until it falls into the sea.

Formally, the points at which the stone touches the water surface will have the following coordinates: ff, f+(f−1)f + (f - 1), f+(f−1)+(f−2)f + (f - 1) + (f - 2), ... , f+(f−1)+(f−2)+…+1f + (f - 1) + (f - 2) + \ldots + 1 (assuming that 00 is the coordinate of the shoreline).

Once, while walking along the embankment of Vladivostok in the evening, Vika saw a group of guys skipping stones across the sea, launching them from the same point with different forces.

She became interested in what is the maximum number of guys who can launch a stone with their force fif_i, so that all fif_i are different positive integers, and all nn stones touched the water at the point with the coordinate xx (assuming that 00 is the coordinate of the shoreline).

After thinking a little, Vika answered her question. After that, she began to analyze how the answer to her question would change if she multiplied the coordinate xx by some positive integers x1x_1, x2x_2, ... , xqx_q, which she picked for analysis.

Vika finds it difficult to cope with such analysis on her own, so she turned to you for help.

Formally, Vika is interested in the answer to her question for the coordinates X1=x⋅x1X_1 = x \cdot x_1, X2=X1⋅x2X_2 = X_1 \cdot x_2, ... , Xq=Xq−1⋅xqX_q = X_{q-1} \cdot x_q. Since the answer for such coordinates can be quite large, find it modulo MM. It is guaranteed that MM is prime.

在维卡的家乡符拉迪沃斯托克,有一片美丽的海洋。

人们常常能看到孩子们打水漂。这一过程是将石子以较小的角度抛向海面,使其飞行较远距离,并在水面上多次弹跳。

维卡曾多次打水漂,她知道:若从海岸线垂直向海中以力度 ff 抛出石子,则石子首次接触水面的位置距海岸线为 ff;随后弹起,并在距前一次接触点 f−1f - 1 的位置再次触水。石子将继续沿直线飞行,且每次触水点之间的距离逐次减小 11,直至最终沉入海中。

形式化地,石子接触水面各点的坐标依次为:
ff,f+(f−1)f + (f - 1),f+(f−1)+(f−2)f + (f - 1) + (f - 2),…,f+(f−1)+(f−2)+…+1f + (f - 1) + (f - 2) + \ldots + 1
(假设海岸线位置的坐标为 00)。

某天傍晚,维卡沿着符拉迪沃斯托克的海堤散步时,看到一群小伙子正朝海面打水漂——他们均从同一点出发,但各自施加的力度不同。

维卡由此产生了一个问题:最多有多少名小伙子能以各自的力度 fif_i 打水漂,使得所有 fif_i 均为互不相同的正整数,且所有 nn 颗石子最终都在坐标为 xx 的同一点处接触水面(仍设海岸线坐标为 00)?

稍作思考后,维卡便得出了该问题的答案。接着,她开始进一步分析:若将坐标 xx 分别乘以若干给定的正整数 x1,x2,…,xqx_1, x_2, \dots, x_q(这些数由她选定用于分析),答案将如何变化?

维卡独自完成此类分析颇为困难,因此她向你求助。

形式化地说,维卡希望得到对应于以下坐标的原问题答案:
X1=x⋅x1X_1 = x \cdot x_1,X2=X1⋅x2X_2 = X_1 \cdot x_2,…,Xq=Xq−1⋅xqX_q = X_{q-1} \cdot x_q。
由于这些坐标对应的答案可能非常大,请对质数 MM 取模输出结果。题目保证 MM 是质数。

输入格式

The first line of the input contains three integers xx (1≤x≤1091 \le x \le 10^9), qq (1≤q≤1051 \le q \le 10^5) and MM (100≤M≤2⋅109100 \le M \le 2 \cdot 10^9) — the initial coordinate for which Vika answered the question on her own, the number of integers xix_i by which Vika will multiply the initial coordinate and prime module MM.

The second line of the input contains qq integers x1,x2,x3,…,xqx_1, x_2, x_3, \ldots, x_q (1≤xi≤1061 \le x_i \le 10^6) — the integers described in the statement.

输入的第一行包含三个整数 xx(1≤x≤1091 \le x \le 10^9)、qq(1≤q≤1051 \le q \le 10^5)和 MM(100≤M≤2⋅109100 \le M \le 2 \cdot 10^9)——分别表示维卡自行回答问题时的初始坐标、维卡将用于乘以初始坐标的整数 xix_i 的个数,以及质数模数 MM。

输入的第二行包含 qq 个整数 x1,x2,x3,…,xqx_1, x_2, x_3, \ldots, x_q(1≤xi≤1061 \le x_i \le 10^6)——即题目描述中提到的那些整数。

输出格式

Output qq integers, where the ii-th number corresponds to the answer to Vika's question for the coordinate XiX_i. Output all the answers modulo MM.

输出 qq 个整数,其中第 ii 个数对应于维卡在坐标 XiX_i 处提出的问题的答案。所有答案均对 MM 取模后输出。

输入输出样例

  • 输入#1

    1 2 179
    2 3

    输出#1

    1
    2
  • 输入#2

    7 5 998244353
    2 13 1 44 179

    输出#2

    2
    4
    4
    8
    16
  • 输入#3

    1000000000 10 179
    58989 49494 8799 9794 97414 141241 552545 145555 548959 774175

    输出#3

    120
    4
    16
    64
    111
    43
    150
    85
    161
    95

说明/提示

In the first sample, to make the stone touch the water at a point with coordinate 22, it needs to be thrown with a force of 22. To make the stone touch the water at a point with coordinate 2⋅3=62 \cdot 3 = 6, it needs to be thrown with a force of 33 or 66.

In the second sample, you can skim a stone with a force of 55 or 1414 to make it touch the water at a point with coordinate 7⋅2=147 \cdot 2 = 14. For the coordinate 14⋅13=18214 \cdot 13 = 182, there are 44 possible forces: 2020, 2929, 4747, 182182.

在第一个样例中,要使石子在坐标为 22 的点处触水,需要以力 22 投掷;要使石子在坐标为 2⋅3=62 \cdot 3 = 6 的点处触水,需要以力 33 或 66 投掷。

在第二个样例中,可以以力 55 或 1414 打水漂,使石子在坐标为 7⋅2=147 \cdot 2 = 14 的点处触水;对于坐标 14⋅13=18214 \cdot 13 = 182,存在 44 种可能的力:2020、2929、4747、182182。

输入解题思路,AI测评打分。不知道怎么写?

首页