题面

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−1 and g(x)=b0+b1x+⋯+bm−1xm−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)=1. Let h(x)=f(x)⋅g(x). Suppose that h(x)=c0+c1x+⋯+cn+m−2xn+m−2.

You are also given a prime number pp. Professor R challenges you to find any tt such that ctct 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.

Input

The first line of the input contains three integers, nn, mm and pp (1≤n,m≤1e6,2≤p≤1e9),  — 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 p is prime.

The second line contains nn integers a0,a1,…,an−1 (1≤ai≤1e9) — ai is the coefficient of xi in f(x).

The third line contains mm integers b0,b1,…,bm−1 (1≤bi≤1e9)  — bi is the coefficient of xi in g(x).

Output

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

Examples

Input
3 2 2
1 1 2
2 1
Output
1
Input
2 2 999999937
2 1
3 1
Output
2

大意

给出两个非负整系数多项式f(x),g(x)和一个质数p,求一个数t,使得对于两个多项式的乘积h(x)=f(x)g(x),其次数为t的项不能被p整除。如果有多种结果,输出任意一个。

题解

这是我ACM校队预备役选拔赛第二场的一道题,在赛场上我没想出来……后来知道解法之后,我不由得赞叹:还是我的技术力太低了吗……不过我在第三场选拔赛的时候成功入选预备役,被我丢弃多时的博客再次被我捡了回来【滑稽】。

回想多项式乘法,我们假设f(x)的i次项系数为ai,g(x)的j次项系数为bj,h(x)的k次项系数为ck,则有ck=a0bk+a1b(k-1)+a2b(k-2)+...+akb0。我们从低位往高位考虑,因为题目保证给出的数p一定是个质数,所以如果ai无法被p整除,bj无法被p整除,那么aibj也一定无法被p整除。所以,我们把两个多项式的系数都对p取模,从低位往高位扫,扫到两个多项式内第一个模p不为0的数,假设是ai,bj。那么,含有项aibj的系数就一定无法被p整除。哪一个系数含有aibj呢?自然是c(i+j)了。下面上赛后补题的AC代码:

#include
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rrep(i,a,b) for(register int i=a;i>=b;--i)
#define grp int T;scanf("%d",&T);rep(C,1,T)
#define grpc int T;cin>>T;rep(C,1,T)
#define etr putchar('\n')
#define in1(a) scanf("%d",&a)
#define in2(a,b) scanf("%d %d",&a,&b)
#define in3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define elif else if
#define mem(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
typedef long long ll;
typedef unsigned long long ull; int n, m, p;
int a[1000010], b[1000010]; int main() { ios::sync_with_stdio(false);
cin.tie(0); cin >> n >> m >> p;
rep(i, 0, n - 1) {
cin >> a[i];
a[i] %= p;
}
rep(i, 0, m - 1) {
cin >> b[i];
b[i] %= p;
}
int f1, f2;
for (f1 = 0; f1 < n; ++f1) {
if (a[f1] != 0) break;
}
for (f2 = 0; f2 < m; ++f2) {
if (b[f2] != 0) break;
}
cout << f1 + f2 << endl; return 0;
} /**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +
*   ┃   ┃ + + + + + +
*   ┃    ┗━━━┓  
*   ┃        ┣┓
*   ┃        ┏┛
*  ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

最新文章

  1. geotrellis使用(二十)geotrellis1.0版本新功能及变化介绍
  2. 安装完magento后,其他电脑无法访问magento,URL自动跳转到http://localhost/magento
  3. sprint3(第八天)
  4. jsp和servlet的区别
  5. 设置input(radio,checkbox)和lable对齐的问题
  6. volley+NetworkImageView实现列表界面的列表项中的左侧图标展现之【实现已经加载的列表项的图标上翻的时候不重新加载】
  7. EventSystem
  8. XML自己定义检查器语法+约束(1)
  9. LOADRUNNER8.1卸载
  10. 关于html控件和服务器控件摁回车后提交按钮的问题
  11. mysql的日志
  12. 使用Jetty搭建Java Websocket Server,实现图像传输
  13. bzoj1858[Scoi2010]序列操作 线段树
  14. Android4.3 屏蔽HOME按键返回桌面详解(源码环境下)
  15. GraphicsMagick+im4java实现高质量大图的处理
  16. android sdk 历史版本下载地址
  17. 【hihocoder 1424】 Asa&#39;s Chess Problem(有源汇上下界网络流)
  18. 【WC2018】即时战略(动态点分治,替罪羊树)
  19. 30 个java编程技巧
  20. SQL语言分类DQL,DML,DDL,DCL,DTL

热门文章

  1. XSS 32个触发事件
  2. 【论文阅读】CVPR2021: MP3: A Unified Model to Map, Perceive, Predict and Plan
  3. Java的重载以及与重写的区别
  4. Golang之框架篇-Windows环境bee工具运行beego
  5. MAVEN setting文件
  6. mysql join 底层原理
  7. InnoDB中加锁?
  8. kafka中的broker 是干什么的?
  9. Java语言的特点有哪些?
  10. 转载:TCP协议如何保证可靠传输