题意:
f(x) = a0+a1*x+ +an*x^(n-1) , g(x) = b0+b1*x+ +bn*x^(n-1),h(x) = f(x)*g(x),问h(x)的哪一项系数模p!=0
题解:
h[i+j]=sigma{a[i]*b[j]}
a[]%p={0,0,0,非0,..}
b[]%p={0,0,非0,..}
ans=两个非0第一次出现的下标之和。
(a[i]*b[j])%p=a[i]%p*b[j]%p!=0
因为h[i+j]=a[i]*b[j]+a[i-1]*b[j+1]+..a[i+1]*b[j-1]+...
非0 0 0
代码
#include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; typedef double db; typedef pair<int,int> pii; typedef vector<int> vi; #define check system("pause") #define all(x) (x).begin(),(x).end() #define de(a) cout<<#a<<" = "<<a<<endl #define dd(a) cout<<#a<<" = "<<a<<" " #define mp make_pair #define pb push_back #define fi first #define se second #define lowbit(a) ((a)&-(a)) #define INF 0x3f3f3f3f const ll mod = 1e9+7; const int N = 1e6+20; #define dep(i,a,b) for(int i=(a);i>=(b);i--) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define mes(p,b) memset(p,b,sizeof(p)) #define sz(x) int(x.size()) int n,m,x,p,ind1=-1,ind2=-1; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>n>>m>>p; rep(i,0,n-1){ cin>>x; if(ind1==-1&&x%p!=0) ind1=i; } rep(i,0,m-1){ cin>>x; if(ind2==-1&&x%p!=0) ind2=i; } cout<<ind1+ind2; return 0; }