Skip to content

Instantly share code, notes, and snippets.

@jen6
Created March 9, 2017 05:46
Show Gist options
  • Save jen6/8c911f22f4b9e95492ab4077e450dd6e to your computer and use it in GitHub Desktop.
Save jen6/8c911f22f4b9e95492ab4077e450dd6e to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
int main() {
int m, n;
scanf("%d %d" , &n, &m);
int arr[1000] = {0, };
//1234567
/*
12 4567 3
12 45 7 6
1 45 7 2 m*i - n
1 45 7
*/
int cnt = 1;
int idx = 1;
while(cnt != n)
{
int i = 1;
while(i < m)
{
if(idx > n)
{
idx = 1;
}
if(!arr[idx])
{
i++;
idx++;
// printf("i : %di\n", i);
}
else
{
idx++;
cnt++;
if(cnt == n)
break;
}
}
if(cnt != n)
printf("%d, ",idx);
arr[idx] = 1;
cnt = 1;
while(arr[idx])
{
idx++;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment