nickel2halide

234.correct

Nov 16th, 2011
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. long MOD = 12582917;
  5.  
  6. int main()
  7. {
  8.   long w, x, y, z;
  9.   long sum = 0; // sum of wxyz over w + x + y + z = 2011 % MOD
  10.   long count = 0;
  11.   for(w = 0; w <= 2011; ++w) {
  12.     for(x = 0; x <= 2011 - w; ++x) {
  13.       for(y = 0; y <= 2011 - w - x; ++y) {
  14.         z = 2011 - w - x - y;
  15.         // printf("%d %d %d %d\n", w, x, y, z);
  16.         sum = (sum + w * x * y * z) % MOD;
  17.         ++count;
  18.       }
  19.     }
  20.   }
  21.  
  22.   printf("sum: %ld, terms: %ld\n", sum, count);
  23.   // should give (2014 choose 7) % MOD, (2014 choose 3)
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment