/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package counting; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.math.BigInteger; import java.util.Scanner; /** * * @author Janette */ public class Counting { static BigInteger one = BigInteger.ONE; static BigInteger two = new BigInteger("2"); static BigInteger five = new BigInteger("5"); static BigInteger[] a = new BigInteger[1001]; public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new File("counting.in")); PrintWriter out = new PrintWriter(new File("counting.out")); int n; a[0] = one; a[1] = two; a[2] = five; calc(); while (in.hasNextInt()) { n = in.nextInt(); out.println(a[n]); //System.out.println(a[n - 1]); } out.close(); } public static void calc() { for (int x = 3; x < a.length; x++) { a[x] = a[x - 1].multiply(two).add(a[x - 2].add(a[x - 3])); } } }