CF1316C.Primitive Primes

普及+/提高

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

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

题目描述

It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.

You are given two polynomials f(x)=a0+a1x+⋯+an−1xn−1f(x) = a_0 + a_1x + \dots + a_{n-1}x^{n-1} and g(x)=b0+b1x+⋯+bm−1xm−1g(x) = b_0 + b_1x + \dots + b_{m-1}x^{m-1}, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 11 for both the given polynomials. In other words, gcd(a0,a1,…,an−1)=gcd(b0,b1,…,bm−1)=1gcd(a_0, a_1, \dots, a_{n-1}) = gcd(b_0, b_1, \dots, b_{m-1}) = 1. Let h(x)=f(x)⋅g(x)h(x) = f(x)\cdot g(x). Suppose that h(x)=c0+c1x+⋯+cn+m−2xn+m−2h(x) = c_0 + c_1x + \dots + c_{n+m-2}x^{n+m-2}.

You are also given a prime number pp. Professor R challenges you to find any tt such that ctc_t isn't divisible by pp. He guarantees you that under these conditions such tt always exists. If there are several such tt, output any of them.

As the input is quite large, please use fast input reading methods.

这是教授 R 教学生涯的最后一节课。每次教授 R 授课时,他都会为学生们准备一道特别的问题。作为他最喜爱的学生,你倾尽心力,最后一次解答这道题。

给定两个多项式 f(x)=a0+a1x+⋯+an−1xn−1f(x) = a_0 + a_1x + \dots + a_{n-1}x^{n-1} 和 g(x)=b0+b1x+⋯+bm−1xm−1g(x) = b_0 + b_1x + \dots + b_{m-1}x^{m-1},其系数均为正整数。保证这两个多项式各自系数的整体最大公约数均为 11,即 gcd⁡(a0,a1,…,an−1)=gcd⁡(b0,b1,…,bm−1)=1\gcd(a_0, a_1, \dots, a_{n-1}) = \gcd(b_0, b_1, \dots, b_{m-1}) = 1。令 h(x)=f(x)⋅g(x)h(x) = f(x)\cdot g(x),并设 h(x)=c0+c1x+⋯+cn+m−2xn+m−2h(x) = c_0 + c_1x + \dots + c_{n+m-2}x^{n+m-2}。

同时给定一个质数 pp。教授 R 向你发起挑战:找出任意一个下标 tt,使得 ctc_t 不能被 pp 整除。他向你保证:在上述条件下,这样的 tt 必然存在。若存在多个满足条件的 tt,输出其中任意一个即可。

由于输入规模较大,请使用快速输入读取方法。

输入格式

The first line of the input contains three integers, nn, mm and pp (1≤n,m≤106,2≤p≤1091 \leq n, m \leq 10^6, 2 \leq p \leq 10^9), — nn and mm are the number of terms in f(x)f(x) and g(x)g(x) respectively (one more than the degrees of the respective polynomials) and pp is the given prime number.

It is guaranteed that pp is prime.

The second line contains nn integers a0,a1,…,an−1a_0, a_1, \dots, a_{n-1} (1≤ai≤1091 \leq a_{i} \leq 10^{9}) — aia_i is the coefficient of xix^{i} in f(x)f(x).

The third line contains mm integers b0,b1,…,bm−1b_0, b_1, \dots, b_{m-1} (1≤bi≤1091 \leq b_{i} \leq 10^{9}) — bib_i is the coefficient of xix^{i} in g(x)g(x).

输入的第一行包含三个整数 nn、mm 和 pp(1≤n,m≤1061 \leq n, m \leq 10^6,2≤p≤1092 \leq p \leq 10^9),其中 nn 和 mm 分别为多项式 f(x)f(x) 和 g(x)g(x) 的项数(即分别比对应多项式的次数大 11),pp 为给定的质数。

保证 pp 是质数。

第二行包含 nn 个整数 a0,a1,…,an−1a_0, a_1, \dots, a_{n-1}(1≤ai≤1091 \leq a_{i} \leq 10^{9}),其中 aia_i 是 f(x)f(x) 中 xix^{i} 项的系数。

第三行包含 mm 个整数 b0,b1,…,bm−1b_0, b_1, \dots, b_{m-1}(1≤bi≤1091 \leq b_{i} \leq 10^{9}),其中 bib_i 是 g(x)g(x) 中 xix^{i} 项的系数。

输出格式

Print a single integer tt (0≤t≤n+m−20\le t \le n+m-2) — the appropriate power of xx in h(x)h(x) whose coefficient isn't divisible by the given prime pp. If there are multiple powers of xx that satisfy the condition, print any.

输出一个整数 tt(0≤t≤n+m−20\le t \le n+m-2)——即多项式 h(x)h(x) 中幂次为 xtx^t 的项的系数不能被给定质数 pp 整除。若存在多个满足条件的幂次,输出任意一个即可。

输入输出样例

  • 输入#1

    3 2 2
    1 1 2
    2 1

    输出#1

    1
  • 输入#2

    2 2 999999937
    2 1
    3 1

    输出#2

    2

说明/提示

In the first test case, f(x)f(x) is 2x2+x+12x^2 + x + 1 and g(x)g(x) is x+2x + 2, their product h(x)h(x) being 2x3+5x2+3x+22x^3 + 5x^2 + 3x + 2, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.

In the second test case, f(x)f(x) is x+2x + 2 and g(x)g(x) is x+3x + 3, their product h(x)h(x) being x2+5x+6x^2 + 5x + 6, so the answer can be any of the powers as no coefficient is divisible by the given prime.

在第一个测试用例中,f(x)f(x) 为 2x2+x+12x^2 + x + 1,g(x)g(x) 为 x+2x + 2,它们的乘积 h(x)h(x) 为 2x3+5x2+3x+22x^3 + 5x^2 + 3x + 2,因此答案可以是 1 或 2,因为系数 3 和 5 均不能被 2 整除。

在第二个测试用例中,f(x)f(x) 为 x+2x + 2,g(x)g(x) 为 x+3x + 3,它们的乘积 h(x)h(x) 为 x2+5x+6x^2 + 5x + 6,因此答案可以是任意幂次,因为给定素数不能整除 h(x)h(x) 的任一系数。

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

首页