Exemplo n.º 1
0
 vector<int> countBits(int num) {
     vector<int> cntBits(num+1,0);
     cntBits[0] = 0;
     cntBits[1] = 1;
     for (int i = 2; i <= num; i++){
         if(i & 1){ // Odd Number
             cntBits[i] = cntBits[i>>1] + 1;
         }else{  // Even Number
Exemplo n.º 2
0
void complement(int upb, Intstack cell, Intstack result) {
  int i = 0, j = 0;
  result->size = 0;
  /* invariant: j == cell->size || i <= cell->it[j] */
  while (i < upb) {
    if (j == cell->size || i < cell->it[j]) {
      if (cntBits(i) % 2 == 0) putint(i, result); 
      i++;
    } else {
      i++;
      j++;
    }
  }
}