fork download
  1. def get_color(x, y):
  2. while x > 1:
  3. # Calculate the size of the triangle at level x
  4. size = 2 * (2 ** (x - 1)) - 1
  5. # Calculate the position of the inverted triangle
  6. if y > size // 2 + 1: # In the inverted triangle
  7. return 0 # Blue
  8. # Check if it's in the left or right triangle
  9. if y <= (size // 2 + 1):
  10. # It's in the left triangle
  11. x -= 1
  12. # y remains the same
  13. else:
  14. # It's in the right triangle
  15. x -= 1
  16. y -= (size // 2 + 1)
  17. return 1 # Red
  18.  
  19. def main():
  20. import sys
  21. input = sys.stdin.read
  22. data = input().splitlines()
  23.  
  24. Q = int(data[0]) # Read number of queries
  25. results = []
  26.  
  27. for i in range(1, Q + 1):
  28. n, y = map(int, data[i].split())
  29. results.append(get_color(n, y))
  30.  
  31. # Print all results, one per line
  32. print('\n'.join(map(str, results)))
  33.  
  34. # Ensure the main function is called when the script is executed
  35. if __name__ == "__main__":
  36. main()
Success #stdin #stdout 0.04s 9868KB
stdin
6
1 1
5 3
8 2
8 6
5 4
6 4
stdout
1
0
1
0
0
0