fork download
  1. #include <cstdio>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main(){
  6. int T, input, remainder;
  7. double n;
  8. scanf("%d", &T);
  9.  
  10. for(int i = 0; i < T; i++) {
  11. if(i) {
  12. printf("\n");
  13. }
  14. scanf("%d", &input);
  15.  
  16. input += 1;
  17. n = floor((-1 + sqrt(1 + 4 * input)) / 4);
  18. remainder = input - (2 * n * (2 * n + 1));
  19. n += 1;
  20.  
  21. if (remainder <= (2 * n - 1)) {
  22. printf("North");
  23. } else if (remainder <= (4 * n - 2)) {
  24. printf("East");
  25. } else if (remainder <= (6 * n - 3)) {
  26. printf("South");
  27. } else {
  28. printf("West");
  29. }
  30. }
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 5276KB
stdin
90
1000
100
10
12
9
1
2
3
4
5
1000
200
50000000
stdout
South
West
East
South
East
East
South
West
West
North
South
West
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East
East