Guest User

Untitled

a guest
Dec 11th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. import java.util.*;
  2. class gp
  3. {
  4.    
  5. public static void main(String []args){
  6. Scanner in=new Scanner(System.in);
  7. int t=in.nextInt();long n=0;int s=0;long a=0;
  8. for(int i=0;i<t;i++){
  9.  n=in.nextLong();
  10.  s=n%2==0?-1:1;
  11.  a=(pow(3,n-1)-s)*3%1000000007;
  12. if(a<0) a+=pow(10,9)+7;
  13. if(a>1000000007) a-=1000000007;
  14. System.out.println(a);
  15.  
  16.    }
  17.    
  18. }
  19.   static  long pow(long n, long exp){
  20.   long halfexp = exp / 2;
  21.   long power, prod, prod2;
  22.  
  23.   prod = n; // hold the product of our multiplication.
  24.  
  25.   for (power = 2; power <=exp; power ++)
  26.   {
  27.     prod *= n%1000000007; //prod = n^power
  28.   }
  29.  
  30.   return prod%1000000007;
  31. }
  32. }
Add Comment
Please, Sign In to add comment