UVa : 11161 (Help My Brother (II))



// http://uva.onlinejudge.org/external/111/11161.html

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

public class Main{

	/**
	 * @param args
	 */
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner (System.in);
		int cases = 0;
		
		BigInteger lineStartWith [] = new BigInteger [1500 + 10];
		lineStartWith [1] = BigInteger.ZERO;
		lineStartWith [2] = BigInteger.ONE;
		
		for ( int i = 3; i <= 1505; i++ ) 
			lineStartWith [i] = lineStartWith [i - 1].add(lineStartWith [i - 2]).add(BigInteger.ONE);
		
		int n = input.nextInt();
		
		while ( n != 0 ) {
			BigInteger median = lineStartWith [n].add(lineStartWith [n + 1]).subtract(BigInteger.ONE).divide(BigInteger.valueOf(2));
			System.out.printf("Set %d:\n", ++cases);
			System.out.println(median);
			n = input.nextInt();
		}
	}
}
Advertisements

2 thoughts on “UVa : 11161 (Help My Brother (II))

  1. Critical Input : 
    7
    8
    9
    10
    1500
    0
    Output : 
    Set 1:
    26
    Set 2:
    43
    Set 3:
    70
    Set 4:
    115
    Set 5:
    28701744751837792382504572139884120147379967713887071940676339260022480759432919082091100482233546321172088309232288923831292573813121811949336397234056265575500939047400236820195426898258659064631250334361870821632035980332554329588700990727932911111805509586445564570998035498070885814859763360107757327357397999
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s