View Code of Problem 3834

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int n;
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            n = sc.nextInt();
            BigInteger sum = new BigInteger("0");
            for (int i = 0;i <= n;i += 2) {
                sum = sum.add(fun(n, i));
            }
            System.out.println(sum);
        }
    }

    public static BigInteger fac(int x) {
        if (x == 0) {
            return BigInteger.ONE;
        }
        else {
            BigInteger temp = new BigInteger(String.valueOf(x));
            return temp.multiply(fac(x - 1));
        }
    }

    public static BigInteger A(int m, int n) {
        return fac(m).divide(fac(m-n));
    }

    public static BigInteger C(int m, int n) {
        return A(m, n).divide(fac(n));
    }

    public static BigInteger fun(int n, int x) {
        BigInteger res = new BigInteger("2");
        res = res.pow(n-x);
        return C(n, x).multiply(res);
    }
}

Double click to view unformatted code.


Back to problem 3834