/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 32ms 788.0 KiB
#4 Accepted 32ms 788.0 KiB
#5 Accepted 32ms 888.0 KiB
#6 Accepted 33ms 788.0 KiB
#7 Accepted 33ms 1.375 MiB
#8 Accepted 42ms 1.324 MiB
#9 Accepted 33ms 1.137 MiB
#10 Accepted 39ms 4.27 MiB
#11 Accepted 36ms 2.77 MiB
#12 Accepted 37ms 3.523 MiB
#13 Accepted 33ms 1.133 MiB
#14 Accepted 34ms 1.273 MiB
#15 Accepted 86ms 836.0 KiB
#16 Accepted 79ms 828.0 KiB
#17 Accepted 32ms 788.0 KiB
#18 Accepted 84ms 864.0 KiB
#19 Accepted 40ms 836.0 KiB
#20 Accepted 38ms 1.238 MiB
#21 Accepted 49ms 5.812 MiB
#22 Accepted 46ms 5.82 MiB
#23 Accepted 84ms 2.77 MiB
#24 Accepted 67ms 8.82 MiB
#25 Accepted 37ms 2.812 MiB
#26 Accepted 318ms 640.0 KiB
#27 Accepted 66ms 3.402 MiB

Code

#include <bits/stdc++.h>
using namespace std;

#define int long long

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int t;
    cin >> t;
    while (t--) {
        int n, x;
        cin >> n >> x;
        vector<int> a(n);
        for (int i = 0; i < n; i++) cin >> a[i];
        
        int q;
        cin >> q;
        
        vector<pair<int, int>> factors;
        int cx = x;
        for (int i = 2; i * i <= cx; i++) {
            int ct = 0;
            while (cx % i == 0) {
                ++ct;
                cx /= i;
            }
            if (ct > 0) factors.push_back({i, ct});
        }
        if (cx > 1) factors.push_back({cx, 1});
        
        int f_size = factors.size();
        vector<vector<int>> pp(f_size, vector<int>(n, 0));
        
        for (int i = 0; i < f_size; i++) {
            int prime = factors[i].first;
            for (int j = 0; j < n; j++) {
                int temp = a[j], ct = 0;
                while (temp % prime == 0) {
                    ct++;
                    temp /= prime;
                }
                pp[i][j] = ct;
            }
        }
        
        for (int i = 0; i < f_size; i++) {
            for (int j = 1; j < n; j++) {
                pp[i][j] += pp[i][j - 1];
            }
        }
        
        while (q--) {
            int l, r;
            cin >> l >> r;
            --l, --r;
            int ct = 0;
            for (int i = 0; i < f_size; i++) {
                int sum = pp[i][r] - (l > 0 ? pp[i][l - 1] : 0);
                if (sum >= factors[i].second) ++ct;
            }
            cout << (ct == f_size ? "Yes" : "No") << "\n";
        }
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2025-03-14 18:36:38
Judged At
2025-03-14 18:36:38
Judged By
Score
100
Total Time
318ms
Peak Memory
8.82 MiB