给定两个序列 \(a,b\),保证每个序列中所有数字的 GCD 为 \(1\),设 \(a*b=c\),给定质数 \(p\),求 \(t\) 使得 \(c_t\) 不能被 \(p\) 整除

\(n,m \leq 10^6, x \leq 10^9\)

Solution

要使 \(c_i \bmod p \neq 0\),则 \(a_0b_i, a_1b_{i-1}, \dots, a_ib_0\) 中至少有一项满足 \(a_xb_y \neq 0 \bmod p\),这要求 \(a_x,b_y \neq 0 \bmod p\),于是我们只需要按下标从小到大找到第一个 \(a_i \neq 0, b_j \neq 0 \bmod p\),那么 \(i+j\) 就是答案

考虑充分性,设第一个不能被 \(p\) 整除的是 \(a_i,b_j\),那么对于 \(c_{i+j}\),它的其它项中一定都含有 \(p\) 因子

#include <bits/stdc++.h>
using namespace std;

const int N = 1000005;
int n,m,p,a[N],b[N];

signed main() {
    ios::sync_with_stdio(false);
    cin>>n>>m>>p;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int j=0;j<m;j++) cin>>b[j];
    int i=0,j=0;
    while(a[i]%p==0) ++i;
    while(b[j]%p==0) ++j;
    cout<<i+j;
}

相关文章:

  • 2022-01-06
  • 2021-12-04
猜你喜欢
  • 2022-12-23
  • 2022-01-04
  • 2022-03-08
  • 2021-09-26
  • 2022-12-23
  • 2021-08-31
  • 2021-10-12
相关资源
相似解决方案