/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 2ms 576.0 KiB
#3 Accepted 83ms 892.0 KiB
#4 Accepted 86ms 688.0 KiB
#5 Accepted 87ms 1.383 MiB
#6 Accepted 97ms 1.645 MiB
#7 Accepted 115ms 6.633 MiB
#8 Accepted 159ms 7.742 MiB
#9 Accepted 118ms 6.559 MiB
#10 Accepted 151ms 46.68 MiB
#11 Accepted 81ms 22.477 MiB
#12 Accepted 113ms 34.445 MiB
#13 Accepted 118ms 8.977 MiB
#14 Accepted 130ms 7.703 MiB
#15 Accepted 125ms 940.0 KiB
#16 Accepted 126ms 792.0 KiB
#17 Accepted 49ms 928.0 KiB
#18 Accepted 126ms 880.0 KiB
#19 Accepted 101ms 1.543 MiB
#20 Accepted 131ms 7.715 MiB
#21 Accepted 221ms 71.129 MiB
#22 Accepted 218ms 71.027 MiB
#23 Accepted 148ms 22.301 MiB
#24 Accepted 404ms 119.973 MiB
#25 Accepted 84ms 22.152 MiB
#26 Accepted 218ms 884.0 KiB
#27 Accepted 168ms 22.586 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-11 02:28:53
Judged By
Score
100
Total Time
404ms
Peak Memory
119.973 MiB