Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerEarth Teachers and students problem solution

YASH PAL, 31 July 2024
In this HackerEarth Teachers and students problem solution There are N students in a class and each student has a number denoted by an array A. The teacher will select three students and give a task to each of them. The first student has to find a number of subsets of students having cumulative xor less than K. The second student has to find a number of subsets of students having cumulative xor equal to K. The third student has to find a number of subsets of students having cumulative xor greater than K. Let the three numbers returned by the selected students are cnt1, cnt2, and cnt3. You need to find the value of :
(cnt1 + cnt2) X 2 + (cnt2 + cnt3) X 2 + (cnt3 + cnt1) X 2 – (cnt1 X 2 + cnt2 X 2 + cnt3 X 2)
HackerEarth Teachers and students problem solution

HackerEarth Teachers and students problem solution.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ff first
#define ss second
#define pb push_back
const ll M=1e9+7;
const ll inf=2e18;
string toString(ll x) { stringstream ss; ss<<x; string s=ss.str(); return s; }
ll toInteger(string s){ stringstream ss(s); ll x=0; ss>>x; return x;}

ll power(ll x,ll n)
{
if(n==0)
return 1;
else if(n%2 == 0)
return power((x*x)%M,n/2);
else
return (x*power((x*x)%M,(n-1)/2))%M;
}

int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll t;
cin>>t;
while(t--)
{
ll n,k;
cin>>n>>k;
for(ll i=0;i<n;i++)
cin>>k;
ll val=power(2LL,n)%M;
cout<<(val*val)%M<<"n";
}
return 0;
}

Second solution

#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if (LOCAL) {
freopen("C:\Users\Dishant\Desktop\Collection-DEV c++\input.txt", "r", stdin);
freopen("C:\Users\Dishant\Desktop\Collection-DEV c++\output.txt", "w", stdout);
}
int t;
assert(cin>>t);
assert(t >= 1 && t <= 20);
while(t--){
ll n, k;
assert(cin>>n);
assert(cin>>k);
assert(n >= 1 && n <= (int)1e5);
assert(k >= 1 && k <= (int)1e5);
ll a[n];
f(i, n) {
assert(cin>>a[i]);
assert(a[i] >= 1 && a[i] <= (int)1e5);
}
ll ans = power(2ll, n);
ans = mul(ans, ans);
cout<<ans<<"n";
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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