fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int Q;
  8. cin >> Q;
  9.  
  10. while (Q--) {
  11. int x, y;
  12. cin >> x >> y;
  13.  
  14. // Determine the level of the triangle
  15. int level = 0;
  16. while (x > 1) {
  17. x /= 2;
  18. level++;
  19. }
  20.  
  21. // Calculate the number of points in the previous level
  22. int prevLevelPoints = pow(2, level - 1) - 1;
  23.  
  24. // Determine the position of the point within the level
  25. int position = y - 1;
  26.  
  27. // If the position is within the top triangle, it's red
  28. if (position < prevLevelPoints) {
  29. cout << 1 << endl;
  30. } else {
  31. // Otherwise, it's in the inverted triangle or the bottom triangle
  32. // We can determine the color by checking if the position is odd or even
  33. cout << (position % 2 == 0 ? 1 : 0) << endl;
  34. }
  35. }
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5284KB
stdin
6
1 1
5 3
8 2
8 6
5 4
6 4
stdout
1
1
1
0
0
0