Primitive Primes
题目大意:
给一个n个项的多项式,系数都是整数,且未知数项为[0,n-1]次,保证所有的n个系数的gcd为1。再同理给出另一个m个项的多项式。再给一个质数p,求他们两个的多项式乘积的系数中,第几次项的系数不是p(p是质数)的倍数,题目保证有解,写出其中任意一个解。
本原多项式的性质
性质如下:
高斯引理:本原多项式的乘积还是本原多项式。
也就是说,找出两个数组第一个不被整除的,将其系数相加就完了。本题解法如下:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6;
void read(int &x)
{
char ch=getchar(); x=0;
for(;ch<'0'||ch>'9';ch=getchar());
for(;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
}
inline void write(int x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
int a[N+5];
int b[N+5];
int main()
{
std::ios::sync_with_stdio(false);
cout.tie(0);
int n,m,p;
read(n);
read(m);
read(p);
int pos1,pos2;
int v=0,u=0;
for(int i=0;i<n;i++)
{
read(a[i]);
if(v==0&&a[i]%p!=0)
{
v=1;
pos1=i;
}
}
for(int i=0;i<m;i++)
{
read(b[i]);
if(u==0&&b[i]%p!=0)
{
u=1;
pos2=i;
}
}
int pos=pos1+pos2;
write(pos);
return 0;
}
自制:超长头文件:
#pragma GCC optimize(3,"Ofast","inline")
#pragma G++ optimize(3)
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef queue<int> q_i;
typedef queue<string> q_s;
typedef queue<double> q_d;
typedef queue<ll> q_ll;
typedef priority_queue<int> pq_i;
typedef priority_queue<string> pq_s;
typedef priority_queue<double> pq_d;
typedef priority_queue<ll> pq_ll;
typedef stack<int> s_i;
typedef stack<string> s_s;
typedef stack<double> s_d;
typedef stack<ll> s_ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,l,r) for(int i=r;i>=l;i--)
#define eif else if
#define mm(dp) memset(dp,0,sizeof(dp))
const double e=2.71828182845;
const double pi = acos(-1.0);
void read(int &x)
{
char ch=getchar(); x=0;
for(;ch<'0'||ch>'9';ch=getchar());
for(;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
}
inline void write(int x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
InvSqrt (double x)//快速开方
{
double xhalf = 0.5f*x;
int i = *(int*)&x;
i = 0x5f3759df - (i >> 1);
x = *(double*)&i;
x = x*(1.5f - xhalf*x*x);
return 1/x;
}