Advertisement
Guest User

Untitled

a guest
Jun 18th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7. class BitSifting
  8. {
  9.     static void Main()
  10.     {
  11.         BigInteger number = BigInteger.Parse(Console.ReadLine());
  12.         int numberOfSieves = int.Parse(Console.ReadLine());
  13.  
  14.         for (int index = 0; index < numberOfSieves; index++)
  15.         {
  16.             BigInteger sieve = BigInteger.Parse(Console.ReadLine());
  17.  
  18.             int count = 0;
  19.  
  20.             while (sieve > 0)
  21.             {
  22.                 int bitToSieve = (int)(sieve & 1);
  23.                 int bitToCheck = (int)((number >> count) & 1);
  24.  
  25.                 if (bitToSieve == 1 && bitToCheck == 1)
  26.                 {
  27.                     number ^= 1 << count;
  28.                 }
  29.                 sieve >>= 1;
  30.                 count++;
  31.             }
  32.         }
  33.  
  34.         int result = 0;
  35.         while (number > 0)
  36.         {
  37.             int check = (int)(number & 1);
  38.             if (check == 1)
  39.             {
  40.                 result++;
  41.             }
  42.             number >>= 1;
  43.         }
  44.  
  45.         Console.WriteLine(result);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement