Flying Jet

   Flying Jet


Problem Description


The jets speed is changed after every mile covered on it's runway. It follows a specific pattern for the speed. Starting from 1 it goes like 1, 7, 16, 21, 81, 63, 256 . . . and so on. Your task is to find out its speed after nth mile.


Input:

The First Line of Input contains T, which denotes the number of test cases. The only line of each test case contains an integer denoting n.


Output:

Print the speed of the jet at the nth mile covered before take Off.


Constraints:

1<=T<=100

1<=N<=60


Example:

Input:

2

5

9

Output:

81

625

Logic Test Case 1


Input (stdin)

10


5 6 3 4 5 1 2 9 8 7


Expected Output


81


63


16


21


81


1


7


625


189


256

Logic Test Case 2


Input (stdin)

5


5 6 3 4 5


Expected Output


81


63


16


21


81





Code Area


import java.io.*;

import java.util.Scanner;

public class TestClass {

public static void main(String[] args)

     { 

       Scanner s=new Scanner(System.in);

       int tests=s.nextInt();

       while(tests>0)

       { 

         int mileN=s.nextInt();

         System.out.println("" +CalculateSpeed(mileN));

         tests--;

      }

}

  public static long CalculateSpeed(int mileN)

  { 

    if(mileN % 2==0)

    { 

     return (long)Math.pow(3,((mileN/2)-1))*7;

    } 

    else

    {

      int terms=(mileN+1)/2;

      long sum=((1+mileN)*terms)/2;

      return (long)Math.pow(sum,2); 

    } 

  } 

}

Post a comment

0 Comments