#include <cstdio> #include <string> #include <vector> using namespace std; vector<string> res{ "", "1", "11", "101", "1001", "11011", "110101", "1011001", "10001011" }; int main() { int z; scanf("%d", &z); while (z--) { int n, k; scanf("%d %d", &n, &k); if (n < (int)res.size()) { printf("%c\n", res[n][k]); } else { if (k == 0 || k == n-1) { printf("1\n"); } else if (k == 1) { printf("%d\n", (n + n*(n-1)/2) % 2); } else { printf("%d\n", 1-n*k%2); } } } return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <cstdio> #include <string> #include <vector> using namespace std; vector<string> res{ "", "1", "11", "101", "1001", "11011", "110101", "1011001", "10001011" }; int main() { int z; scanf("%d", &z); while (z--) { int n, k; scanf("%d %d", &n, &k); if (n < (int)res.size()) { printf("%c\n", res[n][k]); } else { if (k == 0 || k == n-1) { printf("1\n"); } else if (k == 1) { printf("%d\n", (n + n*(n-1)/2) % 2); } else { printf("%d\n", 1-n*k%2); } } } return 0; } |