-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday70.cpp
More file actions
37 lines (31 loc) · 734 Bytes
/
day70.cpp
File metadata and controls
37 lines (31 loc) · 734 Bytes
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
#include <iostream>
#include <list>
using namespace std;
int findLastFriend(int n, int k) {
list<int> friends;
for (int i = 1; i <= n; i++) {
friends.push_back(i);
}
auto it = friends.begin();
while (friends.size() > 1) {
for (int i = 1; i < k; i++) {
it++;
if (it == friends.end()) it = friends.begin();
}
auto toErase = it;
it++;
if (it == friends.end()) it = friends.begin();
friends.erase(toErase);
}
return friends.front();
}
int main() {
int T;
cin >> T;
while (T--) {
int n, k;
cin >> n >> k;
cout << findLastFriend(n, k) << endl;
}
return 0;
}