/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 576.0 KiB
#2 Accepted 3ms 576.0 KiB
#3 Accepted 214ms 1.027 MiB
#4 Accepted 214ms 892.0 KiB
#5 Accepted 210ms 1.023 MiB
#6 Accepted 219ms 1.0 MiB
#7 Accepted 213ms 1.145 MiB
#8 Accepted 223ms 1.09 MiB
#9 Accepted 208ms 1.051 MiB
#10 Accepted 230ms 2.105 MiB
#11 Accepted 212ms 1.418 MiB
#12 Accepted 217ms 1.691 MiB
#13 Accepted 219ms 1.141 MiB
#14 Accepted 222ms 1.133 MiB
#15 Accepted 222ms 872.0 KiB
#16 Accepted 224ms 964.0 KiB
#17 Accepted 206ms 1.09 MiB
#18 Accepted 221ms 1012.0 KiB
#19 Accepted 213ms 1.012 MiB
#20 Accepted 224ms 1.312 MiB
#21 Accepted 255ms 2.906 MiB
#22 Accepted 253ms 2.863 MiB
#23 Accepted 242ms 1.492 MiB
#24 Accepted 288ms 4.5 MiB
#25 Accepted 210ms 1.387 MiB
#26 Accepted 215ms 1.023 MiB
#27 Accepted 415ms 1.777 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define F                first
#define S                second
#define pb               push_back
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define P(ok)            cout << (ok ? "YES\n": "NO\n")
#define __Heart__              ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define ll long long
typedef pair< ll , ll>                   PII;
const int sz = 1e5 + 5 ;
bool notPrime[sz] ;
int n , x , q , l , r , a;
unordered_map<int, vector<int>> prefixSum;
unordered_map < int , int > Xprime;
vector< int > prime ;
void seive()
{
    for(int  i = 4 ; i < sz ; i += 2) notPrime[i] = 1 ;
    int k = sqrt(sz);
    for(int i = 3 ; i < k ; i += 2)
    {
        for(int j = i*i ; j < sz ; j += i) notPrime[j] = 1 ;
    }
    prime.pb(2) ;
    for(int i = 3  ; i < sz ; i += 2) if(!notPrime[i]) prime.pb(i) ;
}
void primefactor(int X)
{
    for(int i = 0; prime[i] <= sqrt(X) && i < prime.size(); i++)
    {
        int cnt = 0 ;
        if(X % prime[i] == 0)
        {
            while(X % prime[i] == 0) X /= prime[i] , cnt++;
            Xprime[prime[i]] = cnt ;
        }

    }
    if(X != 1) Xprime[X] = 1 ;

}
void clr() {
  prefixSum.clear() ;
  Xprime.clear() ;

}
void solve()
{
  cin >> n >> x ;
  primefactor(x) ;
  for (auto &it : Xprime) prefixSum[it.F] = vector<int>(n + 1, 0);

  for(int i = 1 ; i <= n ; i++){
    cin >> a ;
    for(auto it : Xprime) {
         int cnt = 0 ;
         while(a % it.F == 0) a /= it.F , cnt++ ;
        prefixSum[it.F][i] = prefixSum[it.F][i - 1] + cnt ;
    }
  }
  cin >> q ;
  while(q--){
    cin >> l >> r ;
    int ok = 0 ;
    for(auto it : Xprime){
        int cur = prefixSum[it.F][r] - prefixSum[it.F][l - 1] ;
        if(cur >= it.S) ok++ ;
    }
    if(ok == Xprime.size()) cout << "Yes" << endl ;
    else cout << "No" << endl ;
  }
  clr() ;
}
int main()
{
     __Heart__
     seive() ;
     int t ; cin >> t ; while(t--) solve() ;
}

Information

Submit By
Type
Submission
Problem
P1128 Roy and Product
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-01 02:24:12
Judged At
2024-11-11 02:34:16
Judged By
Score
100
Total Time
415ms
Peak Memory
4.5 MiB