Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth AND Sum problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth AND Sum problem solution, we have given an array of N numbers, you have to report the Sum of bitwise AND of all possible subsets of this array. As the answer can be large, report it after taking mod with 10 to power 9 +7.
 
 
HackerEarth AND Sum problem solution

 

 

HackerEarth AND Sum problem solution.

#include<bits/stdc++.h>
using namespace std;
#define test() int t;scanf("%d",&t);for(int tno=1;tno<=t;tno++)
#define mp make_pair
#define pb push_back
#define wl(n) while(n--)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long ll;
typedef unsigned long long llu;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii ;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
#define sz(a) int((a).size())
#define ini(a,v) memset(a,v,sizeof(a))
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scl(x) scanf("%lld",&x)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define scs(s) scanf("%s",s);
#define gcd __gcd
#define debug() printf("heren")
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "t" << #b << " : " << b << endl
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define MOD 1000000007
#define inf ((1<<29)-1)
#define linf ((1LL<<60)-1)
const double eps = 1e-9;
const int MAX = 200009;

ll a[MAX]={0};
ll pw(ll base ,ll expo,ll c)
{
if(expo == 0 )
return 1 ;
ll f = pw(base , expo /2,c) ;
if(expo&1)
return (((f*f)%c)*base)%c ;
return (f*f)%c;
}
int main()
{
int i,j,k;
test(){
int n;
sc(n);
for(i=0;i<n;i++){
scl(a[i]);
}
ll ans = 0LL;
for(ll i=0;i<34;i++){
ll c = 0;
for(j=0;j<n;j++){
if(a[j]&(1LL<<i))
c++;
}
ll y = pw(2,c,MOD);
y = (y - 1 + MOD)%MOD;
y = (y*pw(2,i,MOD))%MOD;
ans = (ans + y + MOD)%MOD;
}
printf("%lldn",ans);
}
return 0;
}
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes