//java solution
import java.io.*;
import java.util.*;
import java.math.*;
class Main
{
public static void main (String args[]) // entry point from OS
{
new Main().Begin();
}
void Begin()
{
try
{
BigInteger b[];
ArrayList abc=new ArrayList(5000);
abc.add(BigInteger.ZERO.toString());
abc.add(BigInteger.ONE.toString());
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.toString());
}
Scanner sc=new Scanner(new File("INPUT.TXT")).useDelimiter("\\D+");
int n;
while(sc.hasNextInt())
{
n=sc.nextInt();
System.out.println("The Fibonacci number for "+n+" is "+abc.get(n));
}
sc.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
import java.io.*;
import java.util.*;
import java.math.*;
class Main
{
public static void main (String args[]) // entry point from OS
{
new Main().Begin();
}
void Begin()
{
try
{
BigInteger b[];
ArrayList abc=new ArrayList(5000);
abc.add(BigInteger.ZERO.toString());
abc.add(BigInteger.ONE.toString());
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.toString());
}
Scanner sc=new Scanner(new File("INPUT.TXT")).useDelimiter("\\D+");
int n;
while(sc.hasNextInt())
{
n=sc.nextInt();
System.out.println("The Fibonacci number for "+n+" is "+abc.get(n));
}
sc.close();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
No comments:
Post a Comment