fork download
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.io.PrintWriter;
  5. import java.util.Arrays;
  6. import java.util.StringTokenizer;
  7.  
  8. public class Game implements Runnable {
  9. private void solve() throws IOException {
  10. int n = nextInt();
  11. int[] grundy = new int[n + 1];
  12. int[] seen = new int[n + 2];
  13. int[] minMoves = new int[n + 1];
  14. Arrays.fill(minMoves, Integer.MAX_VALUE);
  15. Arrays.fill(seen, -1);
  16. for (int i = 0; i <= n; ++i) {
  17. for (int count = 2; count * (count + 1) / 2 <= i; ++count) {
  18. int first = (i - (count * (count - 1)) / 2);
  19. if (first % count != 0) continue;
  20. first /= count;
  21. int xor = 0;
  22. for (int j = 0; j < count; ++j) xor ^= grundy[first + j];
  23. seen[xor] = i;
  24. if (xor == 0) minMoves[i] = Math.min(minMoves[i], count);
  25. }
  26. int j;
  27. for (j = 0; seen[j] == i; ++j);
  28. grundy[i] = j;
  29. }
  30. if (minMoves[n] == Integer.MAX_VALUE)
  31. writer.println(-1);
  32. else
  33. writer.println(minMoves[n]);
  34. for(int i = 0; i <= n; i++)
  35. writer.println(grundy[i]);
  36. }
  37.  
  38. public static void main(String[] args) {
  39. new Game().run();
  40. }
  41.  
  42. StringTokenizer tokenizer;
  43. PrintWriter writer;
  44.  
  45. public void run() {
  46. try {
  47. reader = new BufferedReader(new InputStreamReader(System.in));
  48. tokenizer = null;
  49. writer = new PrintWriter(System.out);
  50. solve();
  51. reader.close();
  52. writer.close();
  53. } catch (Exception e) {
  54. e.printStackTrace();
  55. System.exit(1);
  56. }
  57. }
  58.  
  59. int nextInt() throws IOException {
  60. return Integer.parseInt(nextToken());
  61. }
  62.  
  63. long nextLong() throws IOException {
  64. return Long.parseLong(nextToken());
  65. }
  66.  
  67. double nextDouble() throws IOException {
  68. return Double.parseDouble(nextToken());
  69. }
  70.  
  71. String nextToken() throws IOException {
  72. while (tokenizer == null || !tokenizer.hasMoreTokens()) {
  73. tokenizer = new StringTokenizer(reader.readLine());
  74. }
  75. return tokenizer.nextToken();
  76. }
  77. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
100
compilation info
Main.java:8: error: class Game is public, should be declared in a file named Game.java
public class Game implements Runnable {
       ^
1 error
stdout
Standard output is empty