Pages

Sunday 21 October 2012

UVA - 10862 - Connect the Cable Wires

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        StringBuffer sb = new StringBuffer("");
        String m = "";
        BigInteger fib[] = new BigInteger[4001];
        fib[0] = BigInteger.ONE;
        fib[1] = BigInteger.ONE;
        for (int i = 2; i < 4001; i++) {
            fib[i] = fib[i-1].add(fib[i-2]);
        }
       while(true){
            int x=Integer.parseInt(br.readLine());
            if(x==0)
                break;
            sb.append(fib[x*2-1]).append("\n");
        }
        System.out.print(sb);
    }
}

2 comments:

  1. Hi the information on this blog is just amazing it keeps me coming back time and time again ,personally i met my wife using this site so i couldnt like it any more i have done my best to promote this blog as i know that others need to read this thing ,Thanks for all your effort spent in making this fabulous resource ! ok,nice one Jake

    ReplyDelete
    Replies
    1. Thanks a lot ... I'm really glad that you find this blog helpful ... My main purpose is to offer solutions and new ideas through code to help others ... I am really glad that you use it a lot ... It is my pleasure to help you ... Thanks again

      Delete