CF1817C.Similar Polynomials

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

A polynomial A(x)A(x) of degree dd is an expression of the form A(x)=a0+a1x+a2x2++adxdA(x) = a_0 + a_1 x + a_2 x^2 + \dots + a_d x^d , where aia_i are integers, and ad0a_d \neq 0 . Two polynomials A(x)A(x) and B(x)B(x) are called similar if there is an integer ss such that for any integer xx it holds that

$$ B(x) \equiv A(x+s) \pmod{10^9+7}. $$ </p><p>For two similar polynomials $A(x)$ and $B(x)$ of degree $d$ , you're given their values in the points $x=0,1,\\dots, d$ modulo $10^9+7$ .</p><p>Find a value $s$ such that $B(x) \\equiv A(x+s) \\pmod{10^9+7}$ for all integers $x$$$.

输入格式

The first line contains a single integer dd ( 1d25000001 \le d \le 2\,500\,000 ).

The second line contains d+1d+1 integers A(0),A(1),,A(d)A(0), A(1), \ldots, A(d) ( 0A(i)<109+70 \le A(i) < 10^9+7 ) — the values of the polynomial A(x)A(x) .

The third line contains d+1d+1 integers B(0),B(1),,B(d)B(0), B(1), \ldots, B(d) ( 0B(i)<109+70 \le B(i) < 10^9+7 ) — the values of the polynomial B(x)B(x) .

It is guaranteed that A(x)A(x) and B(x)B(x) are similar and that the leading coefficients (i.e., the coefficients in front of xdx^d ) of A(x)A(x) and B(x)B(x) are not divisible by 109+710^9+7 .

输出格式

Print a single integer ss ( 0s<109+70 \leq s < 10^9+7 ) such that B(x)A(x+s)(mod109+7)B(x) \equiv A(x+s) \pmod{10^9+7} for all integers xx .

If there are multiple solutions, print any.

输入输出样例

  • 输入#1

    1
    1000000006 0
    2 3

    输出#1

    3
  • 输入#2

    2
    1 4 9
    100 121 144

    输出#2

    9

说明/提示

In the first example, A(x)x1(mod109+7)A(x) \equiv x-1 \pmod{10^9+7} and B(x)x+2(mod109+7)B(x)\equiv x+2 \pmod{10^9+7} . They're similar because $$$$B(x) \equiv A(x+3) \pmod{10^9+7}. $$

In the second example, A(x)equiv(x+1)2pmod109+7A(x) \\equiv (x+1)^2 \\pmod{10^9+7} and B(x)equiv(x+10)2pmod109+7B(x) \\equiv (x+10)^2 \\pmod{10^9+7} , hence $$ B(x) \equiv A(x+9) \pmod{10^9+7}. $$$$

首页