fork(2) download
  1. f(a,b){return b?(b&1)*a^f(a*2,b/2):0;}
  2.  
  3.  
  4.  
  5. void test_case(int a, int b, int ab) {
  6. int t = f(a,b);
  7.  
  8. if (t != ab) {
  9. printf("Error! Test case %d @ %d = %d, but f(%d, %d) = %d\n", a, b, ab, a, b, t);
  10. }
  11. else {
  12. printf("%d @ %d = %d\n", a, b, t);
  13. }
  14. }
  15.  
  16. int main() {
  17. test_case(0, 1, 0);
  18. test_case(1, 2, 2);
  19. test_case(9, 0, 0);
  20. test_case(6, 1, 6);
  21. test_case(3, 3, 5);
  22. test_case(2, 5, 10);
  23. test_case(7, 9, 63);
  24. test_case(13, 11, 127);
  25. test_case(5, 17, 85);
  26. test_case(14, 13, 70);
  27. test_case(19, 1, 19);
  28. test_case(63, 63, 1365);
  29. return 0;
  30. }
Success #stdin #stdout 0s 2008KB
stdin
Standard input is empty
stdout
0 @ 1 = 0
1 @ 2 = 2
9 @ 0 = 0
6 @ 1 = 6
3 @ 3 = 5
2 @ 5 = 10
7 @ 9 = 63
13 @ 11 = 127
5 @ 17 = 85
14 @ 13 = 70
19 @ 1 = 19
63 @ 63 = 1365