fork download
  1. import java.io.*;
  2.  
  3. import java.util.*;
  4.  
  5.  
  6. public class Main {
  7.  
  8. static int m=0;
  9.  
  10. public static void main(String[] args)throws IOException{
  11. InputReader in = new InputReader(System.in);
  12. int t = in.nextInt();
  13.  
  14. for(int z=0;z<t;z++){
  15. long n = in.nextLong();
  16. m = in.nextInt();
  17. long a = in.nextLong();
  18. long b = in.nextLong();
  19. long c = in.nextLong();
  20.  
  21. if(n>=m){
  22. pw.println("0");
  23. }
  24.  
  25. else{
  26. long ans = 1;
  27. for(int i=1;i<=(int)n;i++){
  28. ans*=power(i, i);
  29. ans%=m;
  30. }
  31.  
  32. pw.println(ans);
  33. }
  34. }
  35. pw.close();
  36. }
  37.  
  38.  
  39. private static long power(int x, int y) {
  40.  
  41. long temp;
  42. if( y == 0)
  43. return 1;
  44. temp = power(x, y/2)%m;
  45. if (y%2 == 0)
  46. return ((temp%m)*(temp%m))%m;
  47. else
  48. return ((x%m)*((temp%m)*(temp%m))%m)%m;
  49. }
  50.  
  51. static class InputReader {
  52.  
  53. private InputStream stream;
  54. private byte[] buf = new byte[8192];
  55. private int curChar;
  56. private int snumChars;
  57. private SpaceCharFilter filter;
  58.  
  59. public InputReader(InputStream stream) {
  60. this.stream = stream;
  61. }
  62.  
  63. public int snext() {
  64. if (snumChars == -1)
  65. throw new InputMismatchException();
  66. if (curChar >= snumChars) {
  67. curChar = 0;
  68. try {
  69. snumChars = stream.read(buf);
  70. } catch (IOException e) {
  71. throw new InputMismatchException();
  72. }
  73. if (snumChars <= 0)
  74. return -1;
  75. }
  76. return buf[curChar++];
  77. }
  78.  
  79. public int nextInt() {
  80. int c = snext();
  81. while (isSpaceChar(c))
  82. c = snext();
  83. int sgn = 1;
  84. if (c == '-') {
  85. sgn = -1;
  86. c = snext();
  87. }
  88.  
  89. int res = 0;
  90.  
  91. do {
  92. if (c < '0' || c > '9')
  93. throw new InputMismatchException();
  94. res *= 10;
  95. res += c - '0';
  96. c = snext();
  97. } while (!isSpaceChar(c));
  98.  
  99. return res * sgn;
  100. }
  101.  
  102. public long nextLong() {
  103. int c = snext();
  104. while (isSpaceChar(c))
  105. c = snext();
  106. int sgn = 1;
  107. if (c == '-') {
  108. sgn = -1;
  109. c = snext();
  110. }
  111.  
  112. long res = 0;
  113.  
  114. do {
  115. if (c < '0' || c > '9')
  116. throw new InputMismatchException();
  117. res *= 10;
  118. res += c - '0';
  119. c = snext();
  120. } while (!isSpaceChar(c));
  121.  
  122. return res * sgn;
  123. }
  124.  
  125. public String readString() {
  126. int c = snext();
  127. while (isSpaceChar(c))
  128. c = snext();
  129. StringBuilder res = new StringBuilder();
  130. do {
  131. res.appendCodePoint(c);
  132. c = snext();
  133. } while (!isSpaceChar(c));
  134. return res.toString();
  135. }
  136.  
  137. public boolean isSpaceChar(int c) {
  138. if (filter != null)
  139. return filter.isSpaceChar(c);
  140. return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  141. }
  142.  
  143. public interface SpaceCharFilter {
  144. public boolean isSpaceChar(int ch);
  145. }
  146. }
  147.  
  148. }
  149.  
Runtime error #stdin #stdout #stderr 0.12s 320576KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.util.InputMismatchException
	at Main$InputReader.snext(Main.java:66)
	at Main$InputReader.nextInt(Main.java:83)
	at Main.main(Main.java:13)