Accepted
Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool ar[200004];
vector<ll>p;
void seive()
{
ll mxN=200000;
for(int i=0;i<=mxN;i++)
ar[i]=true;
ar[0]=ar[1]=false;
for(int i=2;i*i<=mxN;i++)
{
if(ar[i]==true)
{
for(int j=i*i;j<=mxN;j+=i)
{
ar[j]=false;
}
}
}
for(int i=1;i<=mxN;i++)
{
if(ar[i]==true)
p.push_back(i);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
seive();
ll tc;
cin>>tc;
while(tc--)
{
ll n,x;
cin>>n>>x;
map<ll,ll>mp;
ll u=x;
vector<ll>v(n);
for(int i=0;i<p.size() && p[i]*p[i]<=u;i++)
{
if(u%p[i]==0)
{
while(u%p[i]==0)
{
mp[p[i]]++;
u/=p[i];
}
}
}
if(u>1)
mp[u]++;
vector<ll>ar;
for(auto it:mp)
ar.push_back(it.first);
vector<ll>br[n+1];
for(int i=0;i<n;i++)
{
cin>>v[i];
ll x=v[i];
ll c=0;
if(i==0){
for(int j=0;j<ar.size();j++)
{
br[i].push_back(0);
}
for(int j=0;j<ar.size();j++)
{
c=0;
if(x%ar[j]==0)
{
while(x%ar[j]==0)
{
c++;
x/=ar[j];
}
}
br[i][j]+=c;
}
if(x>1 && mp[x]>1)
{
for(int j=0;j<ar.size();j++)
{
if(ar[j]==x)
br[i][j]++;
}
}
}
else
{
for(int j=0;j<ar.size();j++)
{
br[i].push_back(0);
}
for(int j=0;j<ar.size();j++)
{
c=0;
if(x%ar[j]==0)
{
while(x%ar[j]==0)
{
c++;
x/=ar[j];
}
}
br[i][j]=(br[i-1][j]+c);
}
if(x>1 && mp[x]>1)
{
for(int j=0;j<ar.size();j++)
{
if(ar[j]==x)
br[i][j]++;
}
}
}
}
ll q;
cin>>q;
while(q--)
{
ll l,r;
cin>>l>>r;
l--;
r--;
if(l==0)
{
ll c=0;
for(int j=0;j<ar.size();j++)
{
if(br[r][j]<mp[ar[j]])
{
c=1;
break;
}
}
if(c==1)
cout<<"No\n";
else
cout<<"Yes\n";
}
else
{
ll c=0;
for(int j=0;j<ar.size();j++)
{
if((br[r][j]-br[l-1][j])<mp[ar[j]])
{
c=1;
break;
}
}
if(c==1)
cout<<"No\n";
else
cout<<"Yes\n";
}
}
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1128 Roy and Product
- Contest
- Brain Booster #7
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-11-05 15:58:25
- Judged At
- 2024-11-11 02:29:01
- Judged By
- Score
- 100
- Total Time
- 136ms
- Peak Memory
- 18.078 MiB