Advertisement
ShRooK_MoHameD

my code

Feb 14th, 2023
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.32 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define pi  3.141592653
  4. #define NumOfDigit(w) log10(w) + 1
  5. #define fixed(n) cout << fixed << setprecision(n)
  6. #define getline(s) getline(cin >> ws , s)
  7. #define Ceil(n , m) ((n / m) + (n % m ? 1 : 0))
  8. #define Num_of_Digits(n) ((int)log10(n) + 1)
  9. #define all(s) s.begin(), s.end()
  10. #define rall(s) s.rbegin(), s.rend()
  11. #define cin(v) for (auto&i:v) cin >> i;
  12. #define cout(v) for (auto&i:v) cout << i << " ";
  13. #define cin_2d(vec, n, m) \
  14. for(int i=0;i<n;i++) for(int j=0;j<m&&cin>>vec[i][j];j++);
  15. #define cout_2d(vec, n, m)\
  16. for (int i = 0; i < n; i++, cout << "\n")\
  17. for (int j = 0; j < m && cout << vec[i][j] << " "; j++)
  18. #define cinp(v)  for (auto &i : v)  cin >> i.first >> i.second;
  19. #define coutp(v)  for (auto &i : v) cout << i.first << " " << i.second << "\n";
  20. #define sz(s) (ll)s.size()
  21. #define mini(v) *min_element(all(v))
  22. #define maxi(v) *max_element(all(v))
  23. #define nl "\n"
  24. #define EPS  1e-9
  25. #define OO  2'000'000'000
  26. #define MOD 1'000'000'007
  27. using namespace std;
  28. //****************************************************************************
  29. void ShrOOk() {
  30.  
  31.  ios_base::sync_with_stdio(false),cin.tie(nullptr), cout.tie(nullptr);
  32.     #ifndef ONLINE_JUDGE
  33.     freopen("input.txt","r" , stdin),
  34.     freopen("output.txt","w",stdout);
  35.     #endif
  36. }
  37. //****************************************************************************
  38. vector < ll > factors;
  39. void sieve_factorisation(ll n){
  40.     factors.assign(n + 5 , 2);
  41.     factors[0] = 0;
  42.     factors[1] = 1;
  43.     for(ll i = 2 ; i <= n ; i++){
  44.         for(ll j = i + i ; j <= n ; j += i) factors[j]++;
  45.     }
  46. }
  47. //****************************************************************************
  48.  void solve()
  49.  {
  50.    ll q , n;
  51.    cin >> n >> q;
  52.    vector<ll>v(n) , pre(n+1);
  53.    cin(v);
  54.  
  55.    for(int i=1 ; i<=n ; i++){
  56.     pre[i] = pre[i-1] + v[i-1];
  57.    }
  58.  
  59.    while(q--){
  60.      ll l , r;
  61.      cin >> l >> r;
  62.      if(l==1 and factors[pre[r]] == 2)cout<<"YES"<<nl;
  63.      else if(factors[pre[r]-pre[l-1]] == 2)cout<<"YES"<<nl;
  64.      else cout<<"NO"<<nl;
  65.  
  66.    }
  67.  }
  68. //****************************************************************************
  69.  
  70. int main()
  71. {
  72.   sieve_factorisation((ll)1e7);
  73.    ShrOOk();
  74.    int t=1;
  75.     //  cin>>t;
  76.    while(t--)
  77.    {
  78.    
  79.        solve();
  80.        cout<<nl;
  81.    }
  82.  
  83.  
  84.     return 0;
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement