Skip to content

Instantly share code, notes, and snippets.

@msg7086
Created September 9, 2014 19:26
Show Gist options
  • Select an option

  • Save msg7086/03a1eafe4c13566236bc to your computer and use it in GitHub Desktop.

Select an option

Save msg7086/03a1eafe4c13566236bc to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main() {
int m, n;
scanf("%d%d", &m, &n);
int p[m], j = m - 1;
for(int i = 0; i < m - 1; i++) p[i] = i + 1;
p[m - 1] = 0;
while(p[j] != j) {
for(int i = 0; i < n - 1; i++) j = p[j];
p[j] = p[p[j]];
}
printf("%d\n", j);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment