#include using namespace std; int main() { int p, n; cin >> p >> n; int a = n, x = a, c = 0, xc = 0, ans = 0; for (int i = 2; i < p; i++) { a = (a + n) % p; if (a < x) { c += xc; ans = (ans + c) % 2; x = a; xc = 1; } else if (a == x) { ans = (ans + c) % 2; xc++; } } cout << ans << endl; }