// http://www.spoj.com/problems/ANARC08H/
int n,k,d,i;
while (cin>>n>>k && n != 0) {
for (d=1,i=1; i<=n; d = (d + k) % i++);
cout << n << " " << k << " " << d+1 << endl;
}
Virgin Mobile UAE
hasanal_bukhari [AT] hotmail [DOT] com
http://poj.org/userstatus?user_id=hasan83