Jump
Time Limit: 3000MS Memory Limit:0KB 64bit IO Format:%lld &%llu
SubmitStatusPracticeUVA 1452
Integers 1, 2, 3,..., n are placed on a circle in the increasing order as in The following figure. We want to construct a sequence from these numbers on a circle. Starting with the number 1, we continually go round by picking out Each K -th number and S End to a sequence queue until all numbers on the circle is exhausted. This linearly arranged numbers in the queue is Called jump ( n , k ) sequence where 1 n , k .
Let us compute jump (2) sequence. The first 5 picked numbers is 2, 4, 6, 8, ten as shown in the following. and 3, 7, 1, 9 and 5 would follow. So we get The Jump (10, 2) = [2,4,6,8,10,3,7,1,9,5]. In a similar, we can get the easily jump (3) = [3,6,9,12,2,7,11,4,10,5,1,8,13], jump (13, 10) = [10,7,5,4,6,9,13,8,3,12,1,11,2] and jump (Ten) = [9,10,3,8,1,6,4,5,7,2].
Jump (10,2) = [2,4,6,8,10,3,7,1,9,5]
You write a program to print out the last three numbers of the jump (n, K) for N, C6>k given. For example suppose that n = ten, k = 2, then you should print 1, 9 and 5 on the output file. n OTE that jump (1, k) = [1].
Input
Your program was to read the input from standard input. The input consists of T test Cases. The number of test cases T is given on the first line of the input. Each test case starts with a line containing the integers n and K, where 5n500, 000 and 2k.
Output
Your program is-to-write to standard output. Print the last three numbers of the jump (n, K) in the order of the last third, second an D the last first. The following shows sample input and output for three test cases.
Sample Input
3 10 2 13 10 30000 54321
1#include <stdio.h>2 3 intFunintMintKinti) {4 5 if(i==1)6 return(m+k-1)%m;7 Else8 return(Fun (M-1, k,i-1) +k)%m;9 Ten } One A intMain () - { - intT; thescanf"%d",&T); - while(t--) - { - intn,k,a,b,c; +scanf"%d%d",&n,&k); - if(k%6==1) +A=1, b=2, c=3; A if(k%6==2) atA=2, b=1, c=3; - if(k%6==3) -A=3, b=1, c=2; - if(k%6==4) -A=1, b=3, c=2; - if(k%6==5) inA=2, b=3, c=1; - if(k%6==0) toA=3, b=2, c=1; +A--, b--, c--; - for(intI=4; i<=n;i++) the { *A= (a+k)%i; $b= (b+k)%i;Panax Notoginsengc= (c+k)%i; - } theA++,b++,c++; +printf"%d%d%d\n", a,b,c); A //printf ("%d%d%d\n", Fun (n,k,n-2) +1,fun (n,k,n-1) +1,fun (n,k,n) +1); the } + return 0; -}View Code
UVA 14,528 Jump