View Code of Problem 3692

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            int n = scanner.nextInt();
            if(n == 1){
                System.out.println(3);
                continue;
            }else if(n == 2 || n == 3){
                System.out.println(6);
                continue;
            }
            long a = 6, b = 6, res = 0;
            for (int i = 3; i < n; i++) {
                res = b + 2*a;
                a = b;
                b = res;
            }
            System.out.println(res);
        }
    }
}

Double click to view unformatted code.


Back to problem 3692