1
//
HLOJ 1141 Accepted 15 196 631 C++
2
3 #include < iostream >
4 using namespace std ;
5
6 int tnum ;
7 int inn, inm ;
8
9 int flag[ 110 ] ;
10
11 int main()
12 {
13 while ( cin >> tnum )
14 {
15 while ( tnum -- )
16 {
17 cin >> inn >> inm ;
18
19 memset( flag, 0 , sizeof (flag) ) ;
20
21 int sn = 0 ;
22 int cnt = 1 ;
23 while ( cnt < inn )
24 {
25 for ( int i = 1 ; i <= inm; i ++ )
26 {
27 if ( sn >= inn ) sn = 1 ;
28 else sn = sn + 1 ;
29
30 if ( 1 == flag[sn] ) i -- ;
31 }
32
33 flag[sn] = 1 ;
34 cnt = cnt + 1 ;
35 }
36
37 for ( int i = 1 ; i <= inn; i ++ )
38 {
39 if ( 0 == flag[i] )
40 {
41 printf( " %d\n " , i ) ;
42 break ;
43 }
44 }
45 }
46 }
47 return 0 ;
48 }
2
3 #include < iostream >
4 using namespace std ;
5
6 int tnum ;
7 int inn, inm ;
8
9 int flag[ 110 ] ;
10
11 int main()
12 {
13 while ( cin >> tnum )
14 {
15 while ( tnum -- )
16 {
17 cin >> inn >> inm ;
18
19 memset( flag, 0 , sizeof (flag) ) ;
20
21 int sn = 0 ;
22 int cnt = 1 ;
23 while ( cnt < inn )
24 {
25 for ( int i = 1 ; i <= inm; i ++ )
26 {
27 if ( sn >= inn ) sn = 1 ;
28 else sn = sn + 1 ;
29
30 if ( 1 == flag[sn] ) i -- ;
31 }
32
33 flag[sn] = 1 ;
34 cnt = cnt + 1 ;
35 }
36
37 for ( int i = 1 ; i <= inn; i ++ )
38 {
39 if ( 0 == flag[i] )
40 {
41 printf( " %d\n " , i ) ;
42 break ;
43 }
44 }
45 }
46 }
47 return 0 ;
48 }