fork download
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Main
  5. {
  6. static int n,k;
  7. public void frontAndBack(long raise,int k)
  8. {
  9. int length=String.valueOf(raise).length();
  10.  
  11. long frontTemp=raise;
  12.  
  13. String front = String.valueOf((int)(frontTemp/Math.pow(10, length-1))).toString();
  14. frontTemp=(long) (frontTemp%Math.pow(10, length-1));
  15.  
  16. for(int i=1;i<length && i<k;i++)
  17. {
  18. long quo,rem;
  19. quo=(long) (frontTemp/Math.pow(10, length-i-1));
  20. rem=(long) (frontTemp%Math.pow(10, length-i-1));
  21.  
  22. front=front+String.valueOf(quo).toString();
  23. frontTemp=rem;
  24.  
  25. }
  26. System.out.print(front+" ");
  27.  
  28. long backTemp=raise;
  29.  
  30. String back = String.valueOf((int)(backTemp%Math.pow(10, 1))).toString();
  31. backTemp=(long) (backTemp/Math.pow(10, 1));
  32.  
  33.  
  34. for(int i=1;i<length && i<k;i++)
  35. {
  36. long quo,rem;
  37.  
  38. quo=(long)(backTemp/Math.pow(10, 1));
  39. rem=(long)(backTemp%Math.pow(10, 1));
  40.  
  41. back=String.valueOf(rem).toString()+back;
  42. backTemp=quo;
  43.  
  44.  
  45. }
  46. System.out.println(back);
  47. }
  48.  
  49. public void calc()
  50. {
  51. long raise=(long)Math.pow(n,n);
  52. frontAndBack(raise,k);
  53. }
  54.  
  55. public static void main(String[] args)
  56. {
  57. Scanner in=new Scanner(System.in);
  58.  
  59. int t=in.nextInt();
  60.  
  61. while(t-->0)
  62. {
  63. n = in.nextInt();
  64. k = in.nextInt();
  65. new Main().calc();
  66. }
  67. }
  68. }
Success #stdin #stdout 0.1s 380672KB
stdin
2
4 2
9 3
stdout
25 56
387 489