1158

#include <stdio.h>
#include <stdlib.h>


int main(void){
    // n과 k 입력 받기
    int n = 0, k = 0;
    scanf("%d %d", &n, &k);

    // 배열 1로 초기화 
    int *arr = malloc(sizeof(int)* n);
    for(int i = 0; i < n; i++){
        arr[i] = 1;
    }

    int k_count = k, index = k, print_count = 0;
    printf("<");
    while(1){
        // 만약 모두 출력했으면 중단
        if(n == print_count){
            break;
        }

        // 아직 출력이 안 된 요소일 경우
        if(arr[index-1]){
            // k_count가 k랑 다르면 k_count++
            if(k_count != k){
                k_count++;
            }

            // k_count랑 k가 같으면 
            // 해당 index-1 요소 0으로 초기화, index 번호 출력 
            // 출력 카운트 증가, k 카운트 초기화
            if(k_count == k){
                print_count ++;
                if(n == print_count){ // 마지막 출력 부분일 경우
                    printf("%d>", index);
                }
                else{
                    printf("%d, ", index);
                }
                
                k_count = 0;
                arr[index-1] = 0;
                
            }  
        }

        // index 번호 증가시키기
        index++;
        if(index > n){ // index번호가 n보다 크면 -n 해주기
            index -= n;
        }
        
    }

    free(arr);
    return 0;
}

+ Recent posts