fork download
  1. #include <stdio.h>
  2.  
  3. int main(){
  4. int n,k;
  5. scanf("%d %d",&n,&k);
  6.  
  7. int arr[n];
  8. for(int i = 0 ; i < n ; i++){
  9. arr[i] = i+1;
  10. }
  11.  
  12. int out=0;
  13. for(int i = k-1 ; i < n*k; i+=k){
  14. printf("%d ",arr[i%(n-out)]);
  15.  
  16. for(int j = i%(n-out) ; j < n-out-1 ; j++){
  17. arr[j] = arr[j+1];
  18. }
  19. out++;
  20. }
  21. return 0;
  22. }
  23.  
Success #stdin #stdout 0.01s 5284KB
stdin
7 3
stdout
3 7 5 6 4 2 1