The subset size should be greater than or equal to 2.
How can I speed up this code?
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<malloc.h>
#include <iostream>
#include <vector>
long long int set[100000];
long long int counter, j;
long long int ans,min,count;
bool ha;
long long int pow_set_size;
long long int power[100000];
void printPowerSet(long long int set_size)
{
pow_set_size =power[set_size];
count=4;
for(counter = 3; counter < pow_set_size; counter++)
{
ha=0;
if(counter!=count)
{
for(j = 0; j < set_size; j++)
{
if(counter & (1<<j))
{
if(!ha)
{
ans=set[j];
ha=1;
}
else
{
ans=((ans) & (set[j]));
}
}
}
// printf("%lld\n",ans);
if(counter==3)
{
min=ans;
}
else if(min>ans)
{
min=ans;
}
}
else
{
count=count*2;
}
}
printf("%lld\n",min);
}
void pre()
{
power[0]=1;
for(int i=1;i<=100000;i++)
{
power[i]=power[i-1]*2;
}
}
int main()
{
long long int test;
long long int len;
long long int a;
scanf("%lld",&test);
pre();
while(test--)
{
scanf("%lld",&len);
for(int i=0;i<len;i++)
{
scanf("%lld",&set[i]);
}
printPowerSet(len);
}
return 0;
}
<iostream>
and<vector>
. Are you still trying to implement it in C++ specifically? \$\endgroup\$