#include using namespace std; typedef long long ll; int main(){ ll p,n;cin >> p >> n; if(p==2){ cout << 0 << endl; return 0; } bool f=true; if(n>p-n){ f=false; n=p-n; } if(n==1){ if(f){ cout << 0 << endl; } else{ if(((p-1)*p/2)%2==1){ cout << 1 << endl; } else{ cout << 0 << endl; } } return 0; } ll t=p/n; ll k=t*(t+1)/2; if(f){ if(k%2==1){ cout << 1 << endl; } else{ cout << 0 << endl; } } else{ if((k%2==1)^(((p-1)*p/2)%2==0)){ cout << 1 << endl; } else{ cout << 0 << endl; } } }