Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class gp
- {
- public static void main(String []args){
- Scanner in=new Scanner(System.in);
- int t=in.nextInt();long n=0;int s=0;long a=0;
- for(int i=0;i<t;i++){
- n=in.nextLong();
- s=n%2==0?-1:1;
- a=(pow(3,n-1)-s)*3%1000000007;
- if(a<0) a+=pow(10,9)+7;
- if(a>1000000007) a-=1000000007;
- System.out.println(a);
- }
- }
- static long pow(long n, long exp){
- long halfexp = exp / 2;
- long power, prod, prod2;
- prod = n; // hold the product of our multiplication.
- for (power = 2; power <=exp; power ++)
- {
- prod *= n%1000000007; //prod = n^power
- }
- return prod%1000000007;
- }
- }
Add Comment
Please, Sign In to add comment