Advertisement
Guest User

Untitled

a guest
Jun 18th, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 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.             for (int bit = 0; bit < 64; bit++)
  19.             {
  20.                 BigInteger bitToCheck = (number >> bit) & 1;
  21.                 if (bitToCheck == 1)
  22.                 {
  23.                     BigInteger bitToSieve = (sieve >> bit) & 1;
  24.                     number ^= bitToSieve << bit;
  25.                 }
  26.             }
  27.         }
  28.  
  29.         int result = 0;
  30.         while (number > 0)
  31.         {
  32.             int check = (int)(number & 1);
  33.             if (check == 1)
  34.             {
  35.                 result++;
  36.             }
  37.             number >>= 1;
  38.         }
  39.  
  40.         Console.WriteLine(result);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement