/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 47ms 872.0 KiB
#4 Accepted 26ms 788.0 KiB
#5 Accepted 28ms 844.0 KiB
#6 Accepted 27ms 912.0 KiB
#7 Accepted 29ms 1.02 MiB
#8 Accepted 57ms 1004.0 KiB
#9 Accepted 28ms 1.02 MiB
#10 Accepted 33ms 2.316 MiB
#11 Accepted 30ms 1.52 MiB
#12 Accepted 53ms 1.91 MiB
#13 Accepted 51ms 1.02 MiB
#14 Accepted 28ms 1.02 MiB
#15 Accepted 50ms 788.0 KiB
#16 Accepted 42ms 788.0 KiB
#17 Accepted 50ms 788.0 KiB
#18 Accepted 69ms 788.0 KiB
#19 Accepted 31ms 888.0 KiB
#20 Accepted 31ms 1.02 MiB
#21 Accepted 37ms 3.129 MiB
#22 Accepted 65ms 3.0 MiB
#23 Accepted 83ms 1.52 MiB
#24 Accepted 72ms 4.52 MiB
#25 Accepted 30ms 1.52 MiB
#26 Accepted 135ms 636.0 KiB
#27 Accepted 56ms 2.023 MiB

Code

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp> 
#include<ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int , null_type,less<int> , rb_tree_tag,tree_order_statistics_node_update>
#define int64 long long int
#define endl '\n'
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds; 
const double PI = acos(-1);
const int mod = 1e9 + 7;
const int inf = INT_MAX;
const int _inf = INT_MIN;

int pref[10][100005];
int a[100005];

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);

    int tc = 1; cin >> tc;
    while(tc--){

        int n, x; cin >>n >>x;
        vector <pair <int, int>> facts;
        for (int i = 2; i * i <= x; i++)
        {
            int cnt = 0;
            while (x % i == 0)
            {
                x /= i;
                cnt++;
            }
            if (cnt) facts.push_back({i, cnt});
        }
        if (x > 1)
        {
            facts.push_back({x, 1});
        }

        for (int i = 1; i <= n; i++)
        {
            cin >> a[i];



            for (int j = 0; j < facts.size(); j++)
            {
                int pr = facts[j].first;


                int koybar = 0;
                while (a[i] % pr == 0)
                {
                    a[i] /= pr;
                    koybar++;
                }

                pref[j][i] = koybar;
                pref[j][i] += pref[j][i - 1];


            }
        }
        int q; cin >>q;
        while (q--)
        {
            int l, r; cin >>l >>r;
            bool hobe = 1;

            for (int j = 0; j < facts.size(); j++)
            {

                int inside = pref[j][r] - pref[j][l - 1];
                
                if (inside < facts[j].second) hobe = 0;
            }
            if (hobe) cout <<"Yes\n";
            else cout <<"No\n";
        }



    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2025-06-29 19:22:13
Judged At
2025-06-29 19:22:13
Judged By
Score
100
Total Time
135ms
Peak Memory
4.52 MiB