-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathAujasvit and the Circle Game.cpp
75 lines (54 loc) · 2.4 KB
/
Aujasvit and the Circle Game.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Solution by Rahul Surana
***********************************************************
Aujasvit just came up with a new game to play with his friends. N people stand in a circle, each assigned an index from 1 to N in clockwise order. Then the following operation is done N−1 times.
The person with the lowest index holds a coin.
Then, the coin then moves to the next person clockwise M−1 times.
Then, the person who is holding the coin is removed from the circle.
The last person remaining after N−1 operations is the winner.
Aujasvit has already decided on the integer M to be used in the game. Before inviting people to play his game, Aujasvit wants to know the winner if the game has 1 player, 2 players, 3 players, …, X players. That is, you need to output the winner when N=1,N=2,...,N=X.
Input Format
The first line of each input contains T - the number of test cases. The test cases then follow.
The only line of each test case contains two space-separated integers M and X.
Output Format
For each testcase, output X integers A1,A2,…,AX, where Ai is the index of the winner if i people are playing this game.
***********************************************************
*/
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll>
#define vi vector<int>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(a) a.begin(),a.end()
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a) for(int i = 0; i < a; i++)
#define trace(x) cerr<<#x<<" : "<<x<<endl;
#define trace2(x,y) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<" : "<<x<<" | "<<#y<<" : "<<y<<" | "<<#z<<" : "<<z<<endl;
#define fast_io std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main()
{
fast_io;
int t;
cin >> t;
while(t--) {
int m,x;
cin >> m >> x;
m--;
vector<int> ans(x);
ans[0] = 1;
for(int i = 1; i < x; i++){
int z = (m%(i+1)) +1;
if(ans[i-1]<z)ans[i] =ans[i-1];
else ans[i] = ans[i-1]+1;
}
for(int k = 0; k < x; k++) cout << ans[k] <<" ";
cout <<"\n";
}
}