SHARE
TWEET

Untitled

a guest Jun 20th, 2011 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   #include <stdio.h>
  2.   #include <stdlib.h>
  3.   #include <limits.h>
  4.  
  5.   typedef unsigned long ulong;
  6.   static const ulong ulong_bit = sizeof(ulong) * CHAR_BIT;
  7.  
  8.   static inline ulong search(ulong lb, ulong cb, ulong rb, ulong cnt) {
  9.     if (~0ul == cb)
  10.       cnt += 1;
  11.     else{
  12.       ulong bs;
  13.       for (bs = lb | cb | rb; ~0ul != bs;) {
  14.         ulong b = ~bs & (bs+1);
  15.         bs |= b;
  16.         cnt = search((lb | b) << 1, cb | b, (rb | b) >> 1, cnt);
  17.       }
  18.     }
  19.     return cnt;
  20.   }
  21.  
  22.   static inline ulong nQs(ulong m) { return search(0, ~0ul >> m, 0, 0); }
  23.  
  24.   int main(int argc, char* argv[]) {
  25.     ulong a = argc < 2 ? ulong_bit : atol(argv[1]);
  26.     ulong n = a < ulong_bit ? a : ulong_bit;
  27.     ulong i;    
  28.     for (i=1; i<=n; ++i) printf("%li: %li total solutions\n", i, nQs(i));
  29.     return 0;
  30.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top