高精度递推,用java
View Code
import
java.util.
*
;
import java.io. * ;
import java.math. * ;
public class Main {
static public void main (String[] args) throws FileNotFoundException
{
Scanner cin = new Scanner( new BufferedInputStream(System.in));
// Scanner cin = new Scanner(new FileInputStream("t.txt"));
BigInteger[] f = new BigInteger[ 260 ];
f[ 0 ] = BigInteger.valueOf( 1 );
f[ 1 ] = BigInteger.valueOf( 1 );
for ( int i = 2 ; i <= 250 ; i ++ )
f[i] = f[i - 1 ].add(f[i - 2 ].multiply(BigInteger.valueOf( 2 )));
while (cin.hasNext())
{
int a = cin.nextInt();
System.out.println(f[a]);
}
}
}
import java.io. * ;
import java.math. * ;
public class Main {
static public void main (String[] args) throws FileNotFoundException
{
Scanner cin = new Scanner( new BufferedInputStream(System.in));
// Scanner cin = new Scanner(new FileInputStream("t.txt"));
BigInteger[] f = new BigInteger[ 260 ];
f[ 0 ] = BigInteger.valueOf( 1 );
f[ 1 ] = BigInteger.valueOf( 1 );
for ( int i = 2 ; i <= 250 ; i ++ )
f[i] = f[i - 1 ].add(f[i - 2 ].multiply(BigInteger.valueOf( 2 )));
while (cin.hasNext())
{
int a = cin.nextInt();
System.out.println(f[a]);
}
}
}