// @BEGIN_OF_SOURCE_CODE /* @JUDGE_ID: 17243NT 151 C++ "Brute Force" */ // Send to judge@uva.es #include const int START = 1; const int END = 13; bool eeny[110]; int m, n; bool matchend(); int getnext(int i); int main() { scanf("%d", &n); while(n > 0) { for(m = 1; m < n; m++) { if(matchend()) { printf("%d\n", m); break; } } scanf("%d", &n); } return 0; } int getnext(int i) { int count = 0; i = (i + 1) % n; for(count = 0; count <= n; count++) { if(eeny[i]) return i; i = (i + 1) % n; } return -1; } bool matchend() { int i, j, k; k = START - 1; for(j = 0; j < n; j++) eeny[j] = true; for(i = 1; i < n; i++) { eeny[k] = false; for(j = 0; j < m; j++) { if((k = getnext(k)) == -1) return false; } } if(k == END - 1) return true; return false; } // @END_OF_SOURCE_CODE