Poj Solution 2680

http://poj.org/problem?id=2680

import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
    public static void main(String[] args)
    {
        int n;
        BigInteger two,ans;
        Scanner cin = new Scanner (System.in);
        while(cin.hasNext())
        {
            n = cin.nextInt();
            two = BigInteger.valueOf(2);
            ans = two;
            if(n%2==0)
            {
                ans=ans.pow(n-1).subtract(two).divide(BigInteger.valueOf(3)).add(BigInteger.ONE);
            }
            else
            {
                ans=ans.pow(n-1).subtract(BigInteger.ONE).divide(BigInteger.valueOf(3));
            }
            System.out.println(ans);
        }
    }
}
											
This entry was posted in poj. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *