Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

Even Subset Xor CodeChef Solution

Problem -Even Subset Xor CodeChef Solution

This website is dedicated for CodeChef solution where we will publish right solution of all your favourite CodeChef problems along with detailed explanatory of different competitive programming concepts and languages.
<<Previous CodeChef Problem Next Codechef Problem>>

Even Subset Xor CodeChef Solution in C++17

#include <bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        int n = 0;
        cin >> n;
        ll i = 3, result = 0;
        while (result < n)
        {
            ll temp = i, count_set_bits = 0;
            while (temp)
            {
                if (temp % 2 != 0)
                    count_set_bits++;
                temp = temp >> 1;
            }
            if (count_set_bits % 2 == 0)
            {
                cout << i << " ";
                result++;
            }
            i++;
        }
        cout << endl;
    }
    return 0;
}

Even Subset Xor CodeChef Solution in C++14

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <limits.h>
#include <math.h>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iomanip>
// used for setprecision();
#include <string.h>
// used for memset();
#include <boost/multiprecision/cpp_int.hpp>
#define pll pair<long long, long long>
using namespace std;

#define ll long long
#define mod 1000000007
#define pll pair<long long, long long>
#define endl "\n"
#define LLMAX LONG_LONG_MAX
#define LLMIN LONG_LONG_MIN

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll t = 0;
	cin >> t;
	while (t--) {
	    ll n = 0;
	    cin >> n;
	       
	    ll i = 3, result = 0;
	    while (result < n) {
	        ll temp = i, count_set_bits = 0;
	        while (temp) {
	            if (temp & 1)
	                count_set_bits += 1;
	            temp = temp >> 1;
	        }
	        if (count_set_bits % 2 == 0) {
	            cout << i << " ";
	            result += 1;
	        }
	        i += 1;
	    }
	    cout << endl;
	}
	
	return 0;
}


Even Subset Xor CodeChef Solution in PYTH 3

# cook your dish here
for _ in range(int(input())):
    N = int(input())
    i = 0
    if N == 1:
        print(0)
        continue
    arr = [0]
    while len(arr) < N:
        curval = 2**i + 2**(i + 1)
        arr += [x + curval for x in arr]
        i += 2
    print(*arr[:N])

Even Subset Xor CodeChef Solution in C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#include <limits.h>
#include <stdarg.h>

int Max(int n, ...){
    /* n is the number of elements (including a) */
    
    va_list l; /* declaring the argument list*/
    va_start(l, n); /* initialize the argument list*/
  
    int max = INT_MIN;
    for(int i = 0; i < n; i++){
        int b = va_arg(l, int);
        //printf("%d \t", b);
        if(  b > max )
            max = b;
    }
    va_end(l);
    //printf("%d", max);
    return max;
}

int min(int n, ...){
    /* n is the number of elements  */
    
    va_list l; /* declaring the argument list*/
    va_start(l, n); /* initialize the argument list*/
  
    int min = INT_MAX;
    for(int i = 0; i < n; i++){
        int b = va_arg(l, int);
       // printf("%d \t", b);
        if(  b < min )
            min = b;
    }
    va_end(l);
    return min;
}
/*
#define Max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
*/
#define ll long long 
#define fillArray(A, N) for(ll i = 0; i < N; i++) \
                            scanf("%lli", A + i);
                            
#define printArray(A, N) for(int i = 0; i < N; i++) \
                            printf("%d", A[i]); \
                         printf("\n");
                            

                            
int compareL(const void* a, const void* b){
    ll aa = *(const ll*)a;
    ll bb = *(const ll*)b;
    
    if(aa < bb)
        return -1;
    if(aa > bb)
        return 1;
    return 0;
}
int compareI(const void* a, const void* b){
    int aa = *(const int*)a;
    int bb = *(const int*)b;
    
    if(aa < bb)
        return -1;
    if(aa > bb)
        return 1;
    return 0;
}

int count(int*const array, int n, int size){
    int k = 0;
    for(int i = 0; i < size;i++){
        if(array[i] == n)
            k++;
    }
    return k;
}

bool distinct(int *array, int size){
    qsort(array, size, sizeof(int), compareI);
    int d = 1;
    for(int i = 0; i < size - 1; i++){
        if(array[i] != array[i+1])
            d++;
    }
    if(d % 2 == 0)
        return true;
    if( d < size)
        return true;
    
    return false;
}

bool isValid(int N, int i, int j){
    /* return true if the given coordinates (i, j) are valid */
    if( 0 <= i && i < N && 0 <= j && j < N )
        return true;
    return false;
}

void swapI(int *a, int *b){
    int tmp = *a;
    *a = *b;
    *b = tmp;
}
#define modulo 998244353

ll numberOfContainer(ll k, ll max) 
{
    if (k == max) return 1; 
    if (k == 1) {
        return (max - 1)/2 + 1;
    }
    
    ll res =  1L;
    int test = 0;
    for (int i = 0; i < 32; i++) {
        if (((k >> i) & 0x1) == 1) continue;
        test = i; break; 
    }
    if ((k | (1 << test)) > max) return 1;
    
    for (ll j = k + 1; j <= max; j++) {
        if ((j & k) == k)     res++;
    }
    
    return res;
    
    /*
    //logarithmic version ?
    
    for (int i = 0; i < 32; i++) {
        if (((k >> i) & 0x1) == 1) continue;
        if ((k | (1 << i)) <= max) {
            res += 2;
        
            
        }else break;
    }
    return res;
    */
}

ll modA(ll a, ll b)
{
    return ((a % modulo) + (b % modulo)) % modulo; 
}

ll modP(ll a, ll b)
{
    return ((a % modulo) * (b % modulo)) % modulo;
}

ll modS(ll a, ll b)
{
    return ((a - b) % modulo + modulo) % modulo;
}

ll modE(ll x, ll n) 
{
    ll res = 1;
    x = x % modulo;
    if (x == 0) return 0;
    
    while(n > 0) {
        if ((n & 0x1) == 1) res = modP(res, x);
        n >>= 1;
        x = modP(x, x);
    }
    return res;
}
int setBits(int n ) {
    int k = 0;
    while(n != 0) {
        n = n & (n-1);
        k++;
    }
    return k;
}
int test[1001];
int main(void) 
{
	int T;
	scanf("%d", &T);
	while(T--){
        int N;
        scanf("%d", &N);
        // Let x and y be two not bad number, x xor y is also a not ba d number
        // We just need two find n distincts not bad number( < 2 ^ 20) to fulfill the given condition
        // res = _ _ _ _ _ .... _ _ _ (18 bits) = MSB + LSB
        // 9C2 * 9C2 = 1296 > 1000
        int res = 0x0;
        int MSB = 0, LSB = 0;
        int i = 0;
        
        MSB = LSB = 0;
        for (int j = 8; j >= 0; j--) {
            for (int k = j + 1; k < 9; k++) {
                MSB = (1 << j);
                MSB |= (1 << k);
                for (int j1 = 8; j1 >= 0; j1--) {
                    for (int k1 = j1 + 1; k1 < 9; k1++) {
                        LSB = (1 << j1);
                        LSB |= (1 << k1);
                       // test[i] = ((MSB << 9) | (LSB));
                        i++;
                        printf("%d ", ((MSB << 9) | (LSB)));
                        if (i == N) goto end;
                    }
                }
            }
        } 
        end : ;    
        printf("\n");
        /*
        qsort(test, 1000, sizeof(int), compareI);
        for (int i = 0; i < 1000; i++) {
            if (test[i] == test[i+1] || test[i] >= (1 << 20) || setBits(test[i]) != 4) printf("ERROR");
        }*/
	}
	return 0;
}

Even Subset Xor CodeChef Solution in JAVA

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
    static class sweet
    {
        int diff,cost;
        sweet(int diff,int cost)
        {
            this.diff=diff;
            this.cost=cost;
        }
    }
   /* static long gcd(long x,long y)
    {
        if(y==0)
        return x;
        else
        return gcd(y,x%y);
    }*/
   /* public static String toBin(int x, int len)
    {
        if (len > 0)
        {
            return String.format("%" + len + "s",
                            Integer.toBinaryString(x)).replaceAll(" ", "0");
        }
 
        return null;
    }*/
   /* public static long fact(long a)
    {
        return a*(a-1)/2;
    }*/
  static long gcd(long a, long b)
    {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }
   static class FastReader {
        BufferedReader br;
        StringTokenizer st;
  
        public FastReader()
        {
            br = new BufferedReader(
                new InputStreamReader(System.in));
        }
  
        String next()
        {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
  
        int nextInt() { return Integer.parseInt(next()); }
  
        long nextLong() { return Long.parseLong(next()); }
  
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
  
        String nextLine()
        {
            String str = "";
            try {
                if(st.hasMoreTokens()){
                    str = st.nextToken("\n");
                }
                else{
                    str = br.readLine();
                }
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    static boolean isPrime(long j)
    {
        int s=0;
        for(int k=1;k<=Math.sqrt(j);k++)
        {
            if(j%k==0)
            {
                s++;
            }
        }
        if(s==1)
        return true;
        else
        return false;
    }
    public static int[] solve()
    {
        int m[]=new int[1000];
        int k=0,j=3,a;
        String s;
        while(k<1000)
        {
            a=0;
           s=Integer.toBinaryString(j);
           for(int i=0;i<s.length();i++)
           {
               
               if(s.charAt(i)=='1')
               {
                   a++;
               }
           }
           if(a%2==0)
           {
               m[k]=j;
               k++;
           }
           j++;
        }
        return m;
    }
    public static void main (String[] args) throws java.lang.Exception
    {
       FastReader in = new FastReader();
        int d=0,T,A,B,C,D,i,l,j,G,u,z,Z,k,r;
        long X,Y,cnt;
        long K;
       int N,M,x,y;
      int MIN,MAX;
      int a;
      long b;
        int s=0,min;
        double c,max;
        boolean flag=true;
        int P,Q;
        String S,U,R="";
        int m[]=new int[1000];
        m=solve();
       T=in.nextInt();
       for(i=1;i<=T;i++)
      {  
          
         N=in.nextInt();
         for(j=0;j<N;j++)
         {
             System.out.print(m[j]+" ");
         }
         System.out.println();
}
}
}

Even Subset Xor CodeChef Solution in PYPY 3

for _ in range(int(input())):
    n=int(input())
    f=0
    while(n):
        if not bin(f).count("1")&1:print(f,end=" ");n-=1
        f+=1
    print()

Even Subset Xor CodeChef Solution in PYTH

A = []
cnt = 0
n = 2
while cnt < 1000:
	n += 1
	m = n
	b = 0
	while m > 0:
		b += m%2
		m = m/2
	# endwhile
	if b%2 == 0:
		A.append(n)
		cnt += 1
	# endif
# endwhile
t = int(raw_input())
for i in range(t):
	N = int(raw_input())
	st = ''
	for p in range(N):
		st += str(A[p]) + ' '
	# endfor p
	print st
# endfor i

Even Subset Xor CodeChef Solution in C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Codeforces
{
    public class Program
    {
        private static int _mod = (int)1e9 + 7;

        static void Main(string[] args)
        {
            //Precompute();
            int t = int.Parse(Console.ReadLine());
            for (int i = 0; i < t; i++)
                Solve();
        }

        public static List<int> _nums { get; set; }

        public static void Solve()
        {
            int n = GetInt();
            var a = Enumerable.Range(1, n).Select(DoubleIt).ToList();


#if DEBUG
            Console.Write("Answer is -----------> ");
#endif
            Console.WriteLine(String.Join(" ",a));
        }

        public static int DoubleIt(int n)
        {
            int b = 0;
            for(int i=15; i>=0; i--)
            {
                b *= 4;
                if ((n & (1 << i)) != 0)
                    b += 3;
            }
            return b;
        }

        public static int GetInt() => int.Parse(Console.ReadLine());
        public static long GetLong() => long.Parse(Console.ReadLine());

        public static int[] GetIntArray() => Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
        public static long[] GetLongArray() => Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
        public static double[] GetDoublesArray() => Console.ReadLine().Trim().Split(' ').Select(d => Convert.ToDouble(d, CultureInfo.InvariantCulture)).ToArray();

        public static long Gcd(long a, long b) => b == 0 ? a : Gcd(b, a % b);
        public static long Gcd(long[] a) => a.Aggregate(a[0], (x, y) => Gcd(x, y));
        public static long Lcm(long a, long b) => a * b / Gcd(a, b);
        public static long Lcm(IEnumerable<int> a) => a.Aggregate(1L, (x, y) => Lcm(x, y));
        public static void Swap(ref long a, ref long b)
        {
            long t = a;
            a = b;
            b = t;
        }

        public static void Swap(ref int a, ref int b)
        {
            int t = a;
            a = b;
            b = t;
        }

        public static void OutputSequence(IEnumerable<long> x) => Console.WriteLine($" >>  " + string.Join(", ", x));

        public static string Rev(string s) => string.Concat(s.ToArray().Reverse());

        public static Dictionary<char, long> Frequencies(char[] a)
        {
            var ans = new Dictionary<char, long>();
            foreach (char k in a)
            {
                if (ans.ContainsKey(k))
                    ans[k]++;
                else
                    ans[k] = 1;
            }
            return ans;
        }
    }
}

Even Subset Xor CodeChef Solution in NODEJS

process.stdin.resume();
process.stdin.setEncoding('utf8');

// your code goes here
let input = '';
process.stdin.on('data', (data) => input += data);
process.stdin.on('end', () => {
    input = input.split('\n');
    main();
})

let current = 0;
const readLine = () => input[current++];

const main = () => {
    const size = 1e3 + 1
    const result = new Array(size);
    let current = 1;
        
    for(let i = 0 ; i < 1001 ; i++) {
        while(current.toString(2).match(/1/g).length % 2 !== 0) current++;
        result[i] = current++;
    }
        
    let t = +(readLine());
    while(t--){
        const N = +(readLine());
        console.log(result.slice(0, N).join(' '));
    }
}

Even Subset Xor CodeChef Solution in GO

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
)

func main() {

	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)
		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}
	fmt.Println(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' {
			return s[:i]
		}
	}
	return s
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n int) []int {
	// A[i] = 0 or A[i] = 1 << x | 1 << y
	// A[i] ^ A[j] =  (1 << x | 1 << y) | (1 << a | a << b)
	// C(19, 4) = 19 * 18 * 17 * 16 / 4 * 3 * 2
	A := make([]int, n)
	A[0] = 15
	for i := 1; i < n; i++ {
		A[i] = nextNum(A[i-1])
	}
	return A
}

func nextNum(x int) int {
	// right most set bit
	rightOne := x & -x

	// reset the pattern and set next higher bit
	// left part of x will be here
	nextHigherOneBit := x + rightOne

	// nextHigherOneBit is now part [D] of the above explanation.

	// isolate the pattern
	rightOnesPattern := x ^ nextHigherOneBit

	// right adjust pattern
	rightOnesPattern = (rightOnesPattern) / rightOne

	// correction factor
	rightOnesPattern >>= 2

	// rightOnesPattern is now part [A] of the above explanation.

	// integrate new pattern (Add [D] and [A])
	next := nextHigherOneBit | rightOnesPattern

	return next
}
Even Subset Xor CodeChef Solution Review:

In our experience, we suggest you solve this Even Subset Xor CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Even Subset Xor CodeChef Solution.

Find on CodeChef

Conclusion:

I hope this Even Subset Xor CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

Cognitive Class Answer

CodeChef Solution

Microsoft Learn

Leave a Reply

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