Advertisement
Guest User

Day 15 Redux

a guest
Dec 15th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.80 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAX 2147483647
  3. #define GENUP(GEN,AMT)                      \
  4.     long update_ ## GEN (){                 \
  5.         GEN=(GEN*AMT)%MAX;return GEN;}
  6.  
  7. #define GENUP2(GEN, MODF)                               \
  8.     long update_ ## GEN ## 2 (){                        \
  9.         do{update_ ## GEN ();}while((GEN%MODF)!=0);     \
  10.         return GEN;}
  11.  
  12. long ga,gb;
  13.  
  14. GENUP(ga, 16807)
  15. GENUP(gb, 48271)
  16. GENUP2(ga, 4)
  17. GENUP2(gb, 8)
  18.  
  19. int judge(int iters, long (*ua)(), long (*ub)()){
  20.     ga=703;gb=516;
  21.     int count = 0;
  22.     for(int i=0;i<iters;i++)
  23.         count+=((*ua)()&0xFFFF)==((*ub)()&0xFFFF);
  24.     return count;
  25. }
  26.  
  27. int main(){
  28.     printf("%d\n", judge(40000000, &update_ga, &update_gb));
  29.     printf("%d\n", judge(5000000, &update_ga2, &update_gb2));
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement