fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int N, a, b, ans1, ans2, count = 0, t;
  13. t = Integer.parseInt(br.readLine());
  14.  
  15. List<Integer> list = new ArrayList<Integer>();
  16. while (t > 0) {
  17. String[] line = br.readLine().split(" ");
  18. N = Integer.parseInt(line[0]);
  19. a = Integer.parseInt(line[1]);
  20. b = Integer.parseInt(line[2]);
  21. count = 0;
  22. list.clear();
  23. for (int i = 0; i < N; i++) {
  24. ans1 = (int) Math.pow((i + b), a) ;
  25. //System.out.println(ans1);
  26. ans2 = (int) Math.pow(i, a);
  27. if ((ans1-ans2)%N == 0) {
  28. count++;
  29. list.add(i);
  30. }
  31. }
  32. if (count > 0) {
  33. if (count < 10) {
  34. System.out.println(count);
  35. for (int k : list)
  36. System.out.print(k + " ");
  37. }
  38. else{
  39. System.out.println("10");
  40. for(int k = 0; k < 10;k++)
  41. System.out.print(list.get(k)+" ");
  42. }
  43.  
  44. } else
  45. System.out.println("0");
  46. System.out.println();
  47. t--;
  48. }
  49. }
  50. }
Success #stdin #stdout 0.04s 4386816KB
stdin
1
10 1000000000 1000000000
stdout
8
2 3 4 5 6 7 8 9