Guest User

Untitled

a guest
Dec 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4.  
  5. int64_t judge_one(int64_t a, int64_t b) {
  6. const int pairs = 40000000;
  7. int64_t total = 0;
  8. for (int i=0; i<pairs; i++) {
  9. a = (a * 16807) % INT32_MAX;
  10. b = (b * 48271) % INT32_MAX;
  11.  
  12. total += ~~((a & 0xffff) == (b & 0xffff));
  13. }
  14.  
  15. return total;
  16. }
  17.  
  18. int64_t judge_two(int64_t a, int64_t b) {
  19. const int pairs = 5000000;
  20. int64_t total = 0;
  21. bool a_rdy = false;
  22. bool b_rdy = false;
  23. for (int i=0; i<pairs;) {
  24. if (!a_rdy)
  25. a_rdy = !((a = (a * 16807) % INT32_MAX) % 4);
  26. if (!b_rdy)
  27. b_rdy = !((b = (b * 48271) % INT32_MAX) % 8);
  28.  
  29. if (a_rdy && b_rdy) {
  30. i += ~~!(a_rdy = b_rdy = false);
  31. total += ~~((a & 0xffff) == (b & 0xffff));
  32. }
  33. }
  34.  
  35. return total;
  36. }
  37.  
  38. int main(int argc, char *argv[]) {
  39. char *line = NULL;
  40. size_t size;
  41. int64_t a, b;
  42. getline(&line, &size, stdin);
  43. sscanf(line, "%*s %*s %*s %*s %lld", &a);
  44. getline(&line, &size, stdin);
  45. sscanf(line, "%*s %*s %*s %*s %lld", &b);
  46.  
  47. printf("Inputs: a = %lld, b = %lld\n", a, b);
  48. printf("Total (P1): %lld\n", judge_one(a, b));
  49. printf("Total (P2): %lld\n", judge_two(a, b));
  50.  
  51. return 0;
  52. }
Add Comment
Please, Sign In to add comment