Problem Description
n individuals in a circle, numbered from 1 to n sequentially. From the person numbered 1 starts 1 to K, where the number of people who count K out of the circle, the output of the last left a person's original numbers.
Input
First enter a T, which indicates that there is a T group of data (1<= T <= 10010)
Then there are t-lines, each with 2 positive integers n and K. (1<= n,k<= 20)
Output
For each set of test data, output a number that represents the number of the last person left.
Sample Input
310 37 15 4
Sample Output
471
HINT
For example, a third set of examples: 5 persons in a circle, number 1-5. The first round off 4th, the second round from 5 to start off 1, 3 reported 4,3, the third round from 5 to the 1,5 reported 4,5, fourth Round 1 began to report 4,2 out, the last remaining 1th.
1#include <stdio.h>2 intMain ()3 {4 intI,j,m, out, n,num[ -],*p;5 intcount;6 while(SCANF ("%d", &count)! =EOF)7 {8 for(intk=0; k<count;k++)9 {Tenscanf"%d%d",&n,&m); Onep=num; A for(i=0; i<n;i++) -* (p+i) =i+1; -I=0; thej=0; - out=0; - while( out<n-1) - { + if(* (p+i)! =0) -J + +; + if(j==m) A { at -* (p+i) =0; -j=0; - out++; - } -i++; in if(i==N) -I=0; to } + while(*p==0) -p++; theprintf"%d\n",*p); * $ } Panax Notoginseng - } the + return 1; A}
Wuhan University of Science and Technology acm:1009: Chinese Edition C language Programming tutorial (second Edition) Exercise 6.11