Skip to content

Instantly share code, notes, and snippets.

@jongha
Created May 19, 2019 15:15
Show Gist options
  • Save jongha/6c1379e234ceca59871d4af24dcf32ba to your computer and use it in GitHub Desktop.
Save jongha/6c1379e234ceca59871d4af24dcf32ba to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <list>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
#include <math.h>
//using namespace std;
#define FIND 13
int n;
bool solve(int* v, int pos, int m, int r) {
if(r == 1) return v[pos] == FIND;
if(v[pos] == FIND) return r == 1;
v[pos] = 0;
int t = m;
while(t--) {
++pos;
pos %= n;
if(v[pos] == 0) ++t;
}
return solve(v, pos, m, --r);
}
int main(void) {
while(true) {
scanf("%d", &n);
if(n == 0) break;
int i=0;
while(++i) {
int v[n];
for(int j=1; j<=n; ++j) v[j] = j + 1;
if(solve(v, 0, i, n)) {
printf("%d\n", i);
break;
}
}
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment