#include <stdio.h>
int main(void)
{
int c , d[200] = {0} , e , i , j , k , m , n ;
scanf("%d%d" , & n , & m) ;
for(i = 0 ; i < n ; i ++) d[i] = i + 1 ;
for(k = n , c = e = i = 0 ; k > 1 ; i ++ , i %= n) {
if(d[i]) e ++ ;
if(e == m) {
if(c) printf(" ") ;
printf("%d" , d[i]) ;
e = d[i] = 0 ;
c ++ ;
k -- ;
}
}
printf("\n") ;
for(i = 0 ; i < n ; i ++) if(d[i]) printf("%d\n" , d[i]) ;
}
编译、运行实况:D:\00.Excise\C>g++ -o x x.c
D:\00.Excise\C>x
41 3
3 6 9 12 15 18 21 24 27 30 33 36 39 1 5 10 14 19 23 28 32 37 41 7 13 20 26 34 40
8 17 29 38 11 25 2 22 4 35 16
31
D:\00.Excise\C>
|