forked from improper4/uva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVa00305_Joseph.java
53 lines (46 loc) · 1.21 KB
/
UVa00305_Joseph.java
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
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 241 (305 - Joseph) */
/* SUBMISSION: 11080962 */
/* SUBMISSION TIME: 2012-12-28 02:44:23 */
/* LANGUAGE: 2 */
import java.io.*;
import java.util.*;
public class UVa00305_Joseph {
static boolean simulate(int N, int M) {
int K = N / 2;
int p = -1;
List<Integer> q = new ArrayList<Integer>();
for (int i = 0; i < N; ++i)
q.add(i + 1);
for (int r = 0; r < K; ++r) {
p = (p + M) % q.size();
q.remove(p);
--p;
if (p < 0) p = q.size() - 1;
}
for (int i = 0; i < q.size(); ++i)
if (q.get(i) != i + 1)
return false;
return true;
}
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
/*int[] ans = new int[14];
for (int k = 1; k < 14; ++k)
for (int M = 1; ; ++M)
if (simulate(2 * k, M)) {
ans[k] = M;
System.out.println(M);
break;
}*/
int[] ans = {0, 2, 7, 5, 30, 169, 441, 1872, 7632, 1740, 93313, 459901, 1358657, 2504881};
while (true) {
int K = Integer.parseInt(in.readLine());
if (K == 0) break;
System.out.println(ans[K]);
}
in.close();
System.exit(0);
}
}