#coding = utf8 import collections def ysf(a,b): d = collections.deque(xrange(1,a+1)) while d: d.rotate(-b) print d.pop() if '__main__'==__name__: ysf(13,5)