UVa - 11161 Help My Brother !

//java solution

import java.io.*;
import java.util.*;
import java.math.*;

class Main
{
 

    public static void main (String args[])  // entry point from OS
    {
        Main myWork = new Main();  // create a dinamic instance
        myWork.Begin();            // the true entry point
    }

    void Begin()
    {
 try
 {
 
Scanner sc=new Scanner(System.in);
ArrayList abc=new ArrayList(5000);
  abc.add(BigInteger.ZERO);
  abc.add(BigInteger.ONE);
  BigInteger b1=BigInteger.ZERO;
  BigInteger b2=BigInteger.ONE;
  BigInteger tmp=new BigInteger("0");
  for(int i=2;i<5001;i++)
  {
   tmp=b2;
   b2=b1.add(b2);
   b1=tmp;
   abc.add(i,b2);
  }
int k;
BigInteger rs;
int cnt=0;
for(;;)
{

cnt++;
k=sc.nextInt();
if(k==0) break;
rs = new BigInteger(abc.get(k+3).toString());
rs=rs.add(BigInteger.valueOf(-3));
rs=rs.divide(BigInteger.valueOf(2));
System.out.println("Set "+cnt+":");
System.out.println(rs.toString());
}

sc.close();
}
 catch(Exception e)
 {
  System.out.println(e.getMessage());
  System.exit(0);
 }
    }
}

No comments:

Post a Comment