36 lines
820 B
C
36 lines
820 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int nextIndex(int current_idx, int* arr, int n, int k);
|
|
|
|
int main() {
|
|
int n, k;
|
|
scanf("%d %d",&n, &k);
|
|
int* list = (int*)malloc(sizeof(int)*(n+1));
|
|
for(int i=0; i<=n; i++) {
|
|
list[i] = i;
|
|
}
|
|
|
|
printf("<");
|
|
int len = n, current_idx=1;
|
|
while(len!=0) {
|
|
current_idx = nextIndex(current_idx, list, n, len==n ? k-1 : k);
|
|
if(len==1) printf("%d>\n", list[current_idx]);
|
|
else printf("%d, ",list[current_idx]);
|
|
list[current_idx] = 0;
|
|
len--;
|
|
}
|
|
free(list);
|
|
return 0;
|
|
}
|
|
|
|
int nextIndex(int current_idx, int* arr, int n, int k){
|
|
while(k--){
|
|
do{
|
|
if(current_idx==n) current_idx = 1;
|
|
else current_idx++;
|
|
}while(arr[current_idx]==0);
|
|
}
|
|
return current_idx;
|
|
}
|