Wuhan University of Science and Technology acm:1009: Chinese Edition C language Programming tutorial (second edition) Exercise 6.11

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.