Advertisement
tr00per92

BitSifting

Apr 15th, 2014
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3.  
  4. class Program
  5. {
  6.     static void Main()
  7.     {
  8.         BigInteger num = BigInteger.Parse(Console.ReadLine());
  9.         int n = int.Parse(Console.ReadLine());
  10.         BigInteger[] sito = new BigInteger[n];
  11.         for (int i = 0; i < n; i++)
  12.         {
  13.             sito[i] = BigInteger.Parse(Console.ReadLine());
  14.         }
  15.         for (int i = 0; i < n; i++)
  16.         {
  17.             num &= ~(sito[i]);
  18.         }
  19.         BigInteger bits = 0;
  20.         while (num > 0)
  21.         {
  22.             bits += num % 2;
  23.             num /= 2;
  24.         }
  25.         Console.WriteLine(bits);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement