#include<bits/stdc++.h> using namespace std; int main(){ int n; while(cin>>n){ if(n==0){ break; } printf("%d\n",((int)pow(2,n-1)+1)%n); } return 0; }