Advertisement
Lamms

BitSifting

Jul 22nd, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. using System;
  2.  
  3. class _21BitSifting
  4. {
  5. static void Main()
  6. {
  7. ulong bits = ulong.Parse(Console.ReadLine());
  8. int n = int.Parse(Console.ReadLine());
  9. ulong count = 0;
  10.  
  11. for (int i = 0; i < n; i++)
  12. {
  13. ulong sieve = ulong.Parse(Console.ReadLine());
  14. bits = bits & (~sieve);
  15. }
  16.  
  17.  
  18. while (bits != 0) // until all bits are zero
  19. {
  20. if ((bits & 1) == 1) // check lower bit
  21. {
  22. count++;
  23. bits >>= 1; // shift bits, removing lower bit
  24. }
  25. }
  26. Console.WriteLine(count);
  27.  
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement