fork download
  1. import java.io.*;
  2.  
  3. class Main {
  4.  
  5. static long c = (long)(Math.pow(10,9)+7);
  6.  
  7. public static void main(String[] args) throws IOException {
  8.  
  9. int l = Integer.parseInt(br.readLine());
  10. while (l-- > 0) {
  11. long n = Long.parseLong(br.readLine());
  12. long res = 1;
  13.  
  14. if(n==1){System.out.println(1);continue;}
  15. long d = (n/3);
  16. long rem = (n%3);
  17.  
  18.  
  19. if(rem == 1){d--;rem+=3;}
  20. else if(rem == 0){rem++;} // keeps final ansr non-zero
  21.  
  22. long a = 3;
  23. while (d > 0) {
  24. if ((d & 1) == 1) {
  25. res = (res*a)%c;
  26. }
  27. a = (a*a)%c;
  28. d >>= 1;
  29. }
  30.  
  31.  
  32.  
  33. res = (rem*res)%c;
  34. System.out.println(res);
  35. }
  36. }
  37. }
  38. /*1000000
  39. 619807164
  40. 999999
  41. 154951791
  42. 22
  43. 8748*/
Runtime error #stdin #stdout #stderr 0.07s 32720KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Exception in thread "main" java.lang.NumberFormatException: null
	at java.base/java.lang.Integer.parseInt(Integer.java:620)
	at java.base/java.lang.Integer.parseInt(Integer.java:776)
	at Main.main(Main.java:10)