Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- const int N= 100001;
- int main()
- {
- int n,q; cin>>n>>q;
- vector<int>div[N];
- for(int i=1;i<=n;i++)
- {
- int x; cin>>x;
- for(int j=1;j<=sqrt(x);j++)
- { if(x%j==0 && j*j== x)
- {
- div[j].push_back(i);
- }
- else if(x%j==0)
- {
- div[j].push_back(i);
- div[x/j].push_back(i);
- }
- }
- }
- while(q--)
- {
- int l,r,k; cin>>l>>r>>k;
- int ans = upper_bound(div[k].begin(),div[k].end(),r)-lower_bound(div[k].begin(),div[k].end(),l);
- cout<<ans<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement