D. GCD of an Array
STL
- 题意
见原题
- 思路
见注释
- 代码
ll n,q,a,ans=1;
vector<int> fac[maxn];
map<int,int> mp[maxn];
map<pair<int,int>,int> M;
void init()//分解质因子
{
for(int i=2;i<=2e5;i++)
{
int now=i;
for(int j=2;j*j<=i;j++)
{
while(now%j==0)
{
now/=j;
fac[i].push_back(j);
}
}
if(now!=1) fac[i].push_back(now);
}
}
void add(ll a,ll b)//第a位元素的质因子b
{
mp[a][b]++; //表示因子b在序号为a的元素里出现了多少次
M[{b,mp[a][b]}]++; //表示当前数量的b因子,所有元素中有多少个元素也满足
if(M[{b,mp[a][b]}] == n)//等于n表示n个元素中都有当前数量的b
ans = ans*b %mod;
}
void solve()
{
init();
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>a;
for(auto j:fac[a])
add(i,j);
}
ll pos,x;
while(q--)
{
cin>>pos>>x; //a[pos]*=x
for(auto j:fac[x])
add(pos,j);
Cans
}
}