/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 54ms 824.0 KiB
#4 Accepted 54ms 1.055 MiB
#5 Accepted 51ms 1000.0 KiB
#6 Accepted 55ms 1.199 MiB
#7 Accepted 61ms 3.172 MiB
#8 Accepted 67ms 3.551 MiB
#9 Accepted 64ms 3.012 MiB
#10 Accepted 84ms 17.297 MiB
#11 Accepted 61ms 10.406 MiB
#12 Accepted 74ms 12.941 MiB
#13 Accepted 59ms 4.059 MiB
#14 Accepted 63ms 3.449 MiB
#15 Accepted 64ms 932.0 KiB
#16 Accepted 63ms 928.0 KiB
#17 Accepted 38ms 940.0 KiB
#18 Accepted 62ms 868.0 KiB
#19 Accepted 56ms 1.156 MiB
#20 Accepted 67ms 3.551 MiB
#21 Accepted 111ms 28.883 MiB
#22 Accepted 111ms 28.148 MiB
#23 Accepted 92ms 10.41 MiB
#24 Accepted 156ms 47.18 MiB
#25 Accepted 58ms 10.535 MiB
#26 Accepted 48ms 896.0 KiB
#27 Accepted 108ms 10.848 MiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define life_is_a_race ios::sync_with_stdio(false); cin.tie(nullptr);

bool notprime[32002];
vector<int>allprime;
void seive()
{
    for(int i=2;i<=1000;i++)
    {
        if(notprime[i]) continue;
        for(int j=i+i;j<=32000;j+=i) notprime[j]=true;
    }
    for(int i=2;i<=32000;i++) {if(!notprime[i]) allprime.push_back(i);}
}

int n,x;

int main()
{
    life_is_a_race;
    seive();
    int t; cin>>t; while(t--)
    {
        //cout<<"Case "<<tc<<": ";
        cin >> n >> x;
        vector<int> a(n+1);
        for(int i=1;i<=n;i++) cin>>a[i];
        
        map<int,int> mx;
        for(auto e:allprime)
        {
            if(e>x) break;
            while(x%e==0)
            {
                mx[e]++;
                x /= e;
            }
        }
        if(x > 1) mx[x]++;

        vector<map<int,int>> pfs(n+1);
        for(int i=1;i<=n;i++)
        {
            pfs[i] = pfs[i-1];
            for(auto e:mx)
            {
                while(a[i] % e.first == 0)
                {
                    pfs[i][e.first]++;
                    a[i] /= e.first;
                }
            }
        }
        

        int q; cin>>q; while(q--)
        {
            int l,r; cin>>l>>r;
            bool ok = true;
            
            for(auto e:mx)
            {
                if(pfs[r][e.first]-pfs[l-1][e.first] < e.second) 
                {
                    ok = false;
                    break;
                }
            }
            if(ok) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
    }
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-04 19:52:53
Judged At
2024-11-11 02:33:17
Judged By
Score
100
Total Time
156ms
Peak Memory
47.18 MiB