$|=1; ($n,$k)=<>=~/\d+/g; $v=0; while(1){ if(($n-$v)%($k+1)!=1){ $v+=($n-$v-1)%($k+1); } print"$v\n"; $v=<>+0; last if $v>=$n; }