Skip to content

Commit

Permalink
For iiitv#161
Browse files Browse the repository at this point in the history
  • Loading branch information
Manish Kumar authored Oct 2, 2017
1 parent b003d56 commit d70dfa1
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions 2017/SEPT/COOK86/LIKECS03/LIKECS03.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//Only if a number is power of 2 and is not present, it is required to add.
//Make a pattern till 12-13 and you will realize you can make all
//numbers from taking bitwise or of some of numbers other than power of 2s

//code copyright: Manish Kumar, E&C, IIT Roorkee
#include <iostream>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
#define si(n) scanf("%d",&n)
#define mem(A,i) memset(A, i, sizeof(A))
#define rep(i, start, end) for(int i=start; i<end; i++)
#define repDown(i, start, end) for(ll i=start; i>=end; i--)

bool powerof2(int x){
return x && (!(x&(x-1)));
}

int n,k;
int arr[100005];
#define sz 1<<21

int main(){
int t=1;
si(t);
while(t--){
si(n);
si(k);
rep(i,0,n) si(arr[i]);
bool present[10+(1<<k)];
mem(present,false);
rep(i,0,n) present[arr[i]]=true;
int ans=0;
rep(i,1,1<<k) if(powerof2(i) && present[i]==false) ans++;
cout << ans << endl;
}
return 0;
}

0 comments on commit d70dfa1

Please sign in to comment.