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