fork download
  1. import java.io.*;
  2. import java.util.*;
  3. import java.math.*;
  4. import java.util.concurrent.*;
  5.  
  6. public final class losing_nim
  7. {
  8. static FastScanner sc=new FastScanner(br);
  9. static PrintWriter out=new PrintWriter(System.out);
  10. static Random rnd=new Random();
  11. static long mod;
  12. static int[][] c;
  13. static int n,maxn=505;
  14.  
  15. static void build()
  16. {
  17. c=new int[maxn][maxn];c[0][0]=1;
  18.  
  19. for(int i=1;i<maxn;i++)
  20. {
  21. c[i][0]=1;
  22.  
  23. for(int j=1;j<=i;j++)
  24. {
  25. c[i][j]=add(c[i-1][j],c[i-1][j-1]);
  26. }
  27. }
  28. }
  29.  
  30. static int add(long a,long b)
  31. {
  32. long ret=a+b;
  33.  
  34. if(ret>=mod)
  35. {
  36. ret%=mod;
  37. }
  38.  
  39. return (int)ret;
  40. }
  41.  
  42. static int mul(long a,long b)
  43. {
  44. long ret=a*b;
  45.  
  46. if(ret>=mod)
  47. {
  48. ret%=mod;
  49. }
  50.  
  51. return (int)ret;
  52. }
  53.  
  54. static int pow(long a,long b)
  55. {
  56. long x=1,y=a;
  57.  
  58. while(b>0)
  59. {
  60. if(b%2==1)
  61. {
  62. x=mul(x,y);
  63. }
  64.  
  65. y=mul(y,y);b=b/2;
  66. }
  67.  
  68. return (int)(x%mod);
  69. }
  70.  
  71. static int[] mul(int[] a,int[] b)
  72. {
  73. int[] ret=new int[n+1];
  74.  
  75. for(int i=0;i<b.length;i++)
  76. {
  77. if(b[i]!=0)
  78. {
  79. for(int j=0;j<a.length && i+j<=n;j++)
  80. {
  81. ret[i+j]=add(ret[i+j],mul(b[i],a[j]));
  82. }
  83. }
  84. }
  85.  
  86. return ret;
  87. }
  88.  
  89. public static void main(String args[]) throws Exception
  90. {
  91. n=sc.nextInt();mod=sc.nextLong();build();
  92.  
  93. int[] res=new int[n+1];
  94.  
  95. for(int i=1;i<=n;i++)
  96. {
  97. int[] poly=new int[n+1];poly[0]=1;
  98.  
  99. for(int j=0;j<9;j++)
  100. {
  101. int[] arr=new int[n+1];int val=2*(1<<j);
  102.  
  103. for(int k=0,l=0;k<=n;k+=val,l+=2)
  104. {
  105. arr[k]=c[i][l];
  106. }
  107.  
  108. poly=mul(poly,arr);
  109. }
  110.  
  111. res[i]=poly[n];
  112. }
  113.  
  114. for(int i=1;i<=n;i++)
  115. {
  116. for(int j=i-1;j>=0;j--)
  117. {
  118. int now=mul(res[j],c[i][i-j]);
  119.  
  120. now=mul(now,mod-1);
  121.  
  122. res[i]=add(res[i],now);
  123. }
  124.  
  125. out.println(res[i]);
  126. }
  127.  
  128. out.close();
  129. }
  130. }
  131. class FastScanner
  132. {
  133.  
  134. public FastScanner(BufferedReader in) {
  135. this.in = in;
  136. }
  137.  
  138. public String nextToken() throws Exception {
  139. while (st == null || !st.hasMoreTokens()) {
  140. st = new StringTokenizer(in.readLine());
  141. }
  142. return st.nextToken();
  143. }
  144.  
  145. public String next() throws Exception {
  146. return nextToken().toString();
  147. }
  148.  
  149. public int nextInt() throws Exception {
  150. return Integer.parseInt(nextToken());
  151. }
  152.  
  153. public long nextLong() throws Exception {
  154. return Long.parseLong(nextToken());
  155. }
  156.  
  157. public double nextDouble() throws Exception {
  158. return Double.parseDouble(nextToken());
  159. }
  160. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:6: error: class losing_nim is public, should be declared in a file named losing_nim.java
public final class losing_nim
             ^
1 error
stdout
Standard output is empty