/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 80ms 912.0 KiB
#4 Accepted 78ms 792.0 KiB
#5 Accepted 80ms 1.402 MiB
#6 Accepted 114ms 1.531 MiB
#7 Accepted 103ms 6.504 MiB
#8 Accepted 117ms 7.793 MiB
#9 Accepted 98ms 6.523 MiB
#10 Accepted 149ms 46.52 MiB
#11 Accepted 104ms 22.312 MiB
#12 Accepted 107ms 34.27 MiB
#13 Accepted 111ms 8.934 MiB
#14 Accepted 108ms 7.762 MiB
#15 Accepted 118ms 788.0 KiB
#16 Accepted 113ms 940.0 KiB
#17 Accepted 48ms 892.0 KiB
#18 Accepted 120ms 792.0 KiB
#19 Accepted 93ms 1.41 MiB
#20 Accepted 128ms 7.699 MiB
#21 Accepted 210ms 71.023 MiB
#22 Accepted 205ms 71.035 MiB
#23 Accepted 135ms 22.117 MiB
#24 Accepted 379ms 120.031 MiB
#25 Accepted 74ms 22.27 MiB
#26 Accepted 199ms 844.0 KiB
#27 Accepted 148ms 22.676 MiB

Code

/**
 *  @author:   Binoy Barman
 *  @created:  2024-11-05 21:48:23
**/

#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifdef LOCAL
#include "debug/whereisit.hpp"
#else
#define dbg(...) 42
#endif
#define int long long

map<int, int> primeFactors(int n) {
    map<int, int> pfs;
    while(n % 2 == 0) { 
        pfs[2]++;
        n = n / 2;
    }
    for (int i = 3; i * i <= n; i += 2) { 
        while (n % i == 0) {
            pfs[i]++;
            n = n / i;
        }
    }
    if(n > 2) pfs[n]++;
    return pfs;
}

int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    Too_Many_Jobs {
        int n, x;
        cin >> n >> x;
        auto need = primeFactors(x);
        vector<map<int, int>> a(n + 1), ps(n + 1);
        for(auto z : need) {
            a[0][z.first] = 0;
        }
        for (int i = 1; i <= n; i++) {
            int y;
            cin >> y;
            for(auto z : need) {
                if(y % z.first == 0) {
                    while(y % z.first == 0) {
                        a[i][z.first]++;
                        y /= z.first;
                        if(y == 0) break;
                    }
                } else {
                    a[i][z.first] = 0;
                }
                ps[i][z.first] += a[i][z.first] + ps[i - 1][z.first];
            }
        }
        int q;
        cin >> q;
        while(q--) {
            int l, r;
            cin >> l >> r;
            map<int, int> cur;
            for(auto z : need) {
                cur[z.first] = ps[r][z.first] - ps[l - 1][z.first];
            }
            bool ok = true;
            for(auto z : need) {
                if(z.second > cur[z.first]) {
                    ok = false;
                    break;
                }
            }
            cout << (ok ? "Yes" : "No") << nl;
        }
    }
    
    return 0;
}

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 16:01:37
Judged At
2024-11-05 16:01:37
Judged By
Score
100
Total Time
379ms
Peak Memory
120.031 MiB