Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int primap(int a[],int n,int st,int x)
- {
- int s=st,d=n,poz=-1,m;
- if(x<a[s] or x>a[d])
- return -1;
- while(s<=d)
- {
- m=(s+d)/2;
- if(a[m]==x)
- {
- poz=m;
- d=m-1;
- }
- else if(a[m]>x)
- d=m-1;
- else s=m+1;
- }
- return poz;
- }
- int ultimaap(int a[],int n,int st,int x)
- {
- int s=st,d=n,poz=-1,m;
- if(x<a[s] or x>a[d])
- return -1;
- while(s<=d)
- {
- m=(s+d)/2;
- if(a[m]==x)
- {
- poz=m;
- s=m+1;
- }
- else if(a[m]>x)
- d=m-1;
- else s=m+1;
- }
- return poz;
- }
- int main()
- {
- int n,i,a[100001],nrsol=0,uap,pap,x,p2[33],j;
- cin>>n;
- for(i=1; i<=n; i++)
- cin>>a[i];
- sort(a+1,a+1+n);
- p2[0]=1;
- for(i=1; i<=30; i++)
- p2[i]=p2[i-1]*2;
- for(i=1; i<n; i++)
- {
- for(j=1; j<=30; j++)
- {
- x=p2[j]-a[i];
- if(x>=a[1] and x<=a[n])
- {
- pap=primap(a,n,i+1,x);
- if(pap>-1)
- {
- uap=ultimaap(a,n,i+1,x);
- nrsol+=(uap-pap+1);
- }
- }
- }
- }
- cout<<nrsol;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement