C.プリミティブ素数
問題の意味
二つの与えられた原始多項式、多項式をh(x)を得るために2倍、単に特定の係数H(x)を見つける\(C_Tを\)、Tを出力することができます。
思考
最初= 0、我々はそれを取ることができる!それ(係数)%pをどの手段、pで割り切れない(a_iを\)\最初は%pです!= 0、セット\(b_jが\)第1の数%のP = 0であり、そして我々は、係数の方程式を出ることができる:!
\ [(A_0 B_ {* I + J + A_1} * {I + B_ J-1} + ...)+
a_iを* b_j +(A_ {I + 1} * B_ {J-1} + A_ {I + 2} * B_ {J-2} + ...)\] iが与えられた(\ a_iを\)最小インデックスp、手段で割り切れないかもしれない\(A_0 \)に\(A_ {I-1} \) 、Pで割り切れることができる従って括弧内に残さP項目で割り切れることができます。同様に、括弧内の右辺のために、\(B_0 \)に\(B_ {J-1} \) Pで割り切れることができます。したがって、唯一の中央\(a_iを* b_j \) 、およびに対応するインデックスを出力します。コードの実装
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e6+10; ll a[maxn]; ll b[maxn]; inline ll read() { ll s=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') //处理负数 f=-1; ch=getchar(); //处理其他字符 } while(ch>='0'&&ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; } int main(void){ ll n,m,p; n = read(); m = read(); p = read(); for(int i = 0; i < n; i++){ a[i] = read(); a[i] %= p; } for(int i = 0; i < m; i++){ b[i] = read(); b[i] %= p; } ll ans = 0; for(int i = 0; i < n; i++){ if(a[i]){ ans = i; break; } } for(int i = 0; i < m; i++){ if(b[i]){ ans += i; break; } } printf("%lld\n",ans); return 0; }