Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define fastread()(ios_base::sync_with_stdio(false),cin.tie(NULL));
- #define N 10000010
- #define m 3200
- #define pb push_back
- typedef long long ll;
- //const int N=1e7+2;
- bool prime[N];
- void primefact()
- {
- int i,j;
- prime[0]=prime[1]=1;
- for(i=4; i<=N; i+=2)
- prime[i]=1;
- for(i=3; i<=m; i+=2)
- {
- if(prime[i]==0)
- {
- for(j=i*i; j<=N; j+=i*2)
- prime[j]=1;
- }
- }
- }
- int main()
- {
- fastread();
- primefact();
- int n,i,q;
- scanf("%d",&n);
- int ara[n+1],res[n+3];
- res[0]=0;
- for(i=0; i<n; i++)
- {
- scanf("%d",&ara[i]);
- if(prime[ara[i]]==0)
- res[i+1]=res[i]+1;
- else
- res[i+1]=res[i];
- //cout<<res[i+1]<<" ";
- }
- // cout<<endl;
- scanf("%d",&q);
- while(q--)
- {
- int x,y,z;
- scanf("%d %d %d",&x,&y,&z);
- if(x==1)
- {
- printf("%d\n",res[z]-res[y-1]);
- }
- else
- {
- int temp=ara[y-1];
- ara[y-1]=z;
- if(temp==z)continue;
- else if(prime[temp]==0)
- {
- if(prime[z]==1)
- {
- for(i=y; i<=n; i++)
- {
- res[i]-=1;
- //cout<<res[i]<<" ";
- }
- //cout<<endl;
- }
- }
- else if(prime[z]==0)
- {
- if(prime[temp]==1)
- {
- for(i=y; i<=n; i++)
- {
- res[i]+=1;
- //cout<<res[i]<<" ";
- }
- // cout<<endl;
- }
- }
- }
- }
- return 0;
- }
RAW Paste Data