-
Notifications
You must be signed in to change notification settings - Fork 0
/
1031.cpp
37 lines (37 loc) · 912 Bytes
/
1031.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
// Ivan Carvalho
// Solution to https://www.beecrowd.com.br/judge/problems/view/1031
#include <cstdio>
#include <deque>
#define MAXN 301
using namespace std;
int dp[MAXN][MAXN], vetor[MAXN];
void solve(int n, int m) {
deque<int> simula;
for (int i = 1; i <= n; i++) {
simula.push_back(i);
}
int cortados = 0;
while (simula.size() != 1) {
int davez = simula.front();
simula.pop_front();
if (cortados % m != 0) simula.push_back(davez);
cortados++;
}
dp[n][m] = simula.front();
}
int main() {
for (int i = 1; i <= 100; i++) {
for (int j = 1; j < MAXN; j++) {
solve(i, j);
if (dp[i][j] == 13) {
vetor[i] = j;
break;
}
}
}
int escolhido;
while (scanf("%d", &escolhido) && escolhido) {
printf("%d\n", vetor[escolhido]);
}
return 0;
}