herrDeng網內搜尋

自訂搜尋

Ads

2011年6月2日 星期四

Fibonacci數列

a[0]=0
a[1]=a[2]=1
a[n]=a[n-1]+a[n-2]

利用遞迴公式列出a[n] n=2....40
並比較下列公式







f[2]=1
f[3]=2
f[4]=3
f[5]=5
f[6]=8
f[7]=13
f[8]=21
f[9]=34
f[10]=55
f[11]=89
f[12]=144
f[13]=233
f[14]=377
f[15]=610
f[16]=987
f[17]=1597
f[18]=2584
f[19]=4181
f[20]=6765
f[21]=10946
f[22]=17711
f[23]=28657
f[24]=46368
f[25]=75025
f[26]=121393
f[27]=196418
f[28]=317811
f[29]=514229
f[30]=832040
f[31]=1346269
f[32]=2178309
f[33]=3524578
f[34]=5702887
f[35]=9227465
f[36]=14930352
f[37]=24157817
f[38]=39088169
f[39]=63245986
f[40]=102334155

20 則留言:

B9933100 提到...

import java.util.*;
public class cc{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}

public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));

}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933065 提到...

import java.util.*;
public class cc{
public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\t"+"a("+i+")="+a(i));
}
}
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933061 提到...

import java.util.*;
public class cc{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933066 提到...

import java.util.*;
public class abc{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933106 提到...

import java.util.*;
public class celtics{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933068 提到...

import java.util.*;
public class jjj{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933108 提到...

import java.util.*;
public class ggggg{
public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));
}
}
public static double a(int n)
{
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}

public static void main(String[] args){
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933097 提到...

import java.util.*;
public class fibonacci3{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2,n);
double a2=Math.pow((1-sqrt5)/2,n);
return(a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int[n+1];
f[0]=0;f[1]=1;
for(int i=2;i<=n;i++){
f[i]=f[i-1]+f[i-2];
System.out.println("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));
}
}
public static void main(String[]args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

b9933110 提到...

import java.util.*;
public class Fibonacci{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

b9933064 提到...

import java.util.*;
public class Fibonacci{
public static double a(int n)
{
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2,n);
double a2=Math.pow((1-sqrt5)/2,n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int[n+1];
f[0]=0;f[1]=1;
for(int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("a("+1+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933078 提到...

import java.util.*;
public class Fibonacci{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1= Math.pow((1+sqrt5)/2,n);
double a2= Math.pow((1-sqrt5)/2,n);
return (a1-a2)/sqrt5;
}

public static void f(int n){
int f[]=new int[n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("a("+1+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

b9933094 提到...

import java.util.*;
public class fibonacci{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

b9933075 提到...

import java.util.*;
public class Fibonacci{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

b9933115 提到...

import java.util.*;
public class Fibonacci{
public static double a(int n)
{
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2,n);
double a2=Math.pow((1-sqrt5)/2,n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int[n+1];
f[0]=0;f[1]=1;
for(int i=2; i&lt;=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print(&quot;f[&quot;+i+&quot;]=&quot;+f[i]);
System.out.println(&quot;a(&quot;+1+&quot;)=&quot;+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933073 提到...

import java.util.*;
public class Fibonacci{
public static double a(int n)
{
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2,n);
double a2=Math.pow((1-sqrt5)/2,n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int[n+1];
f[0]=0;f[1]=1;
for(int i=2; i&lt;=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print(&quot;f[&quot;+i+&quot;]=&quot;+f[i]);
System.out.println(&quot;a(&quot;+1+&quot;)=&quot;+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

b9633038 提到...

import java.util.*;
public class celtics{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2,n);
double a2=Math.pow((1-sqrt5)/2,n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));
}
}
public static void main (String[]args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

A9933058 提到...

import java.util.*;
public class y1{
public static double a(int n)
{
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2,n);
double a2=Math.pow((1-sqrt5)/2,n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int[n+1];
f[0]=0;f[1]=1;
for(int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("a("+1+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933085 提到...

import java.util.*;
public class Fibonacci{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}
public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933072 提到...

import java.util.*;
public class Fibonacci{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1= Math.pow((1+sqrt5)/2,n);
double a2= Math.pow((1-sqrt5)/2,n);
return (a1-a2)/sqrt5;
}

public static void f(int n){
int f[]=new int[n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("a("+1+")="+a(i));
}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

B9933116 提到...

import java.util.*;
public class cc{
public static double a(int n){
double sqrt5=Math.sqrt(5);
double a1=Math.pow((1+sqrt5)/2, n);
double a2=Math.pow((1-sqrt5)/2, n);
return (a1-a2)/sqrt5;
}

public static void f(int n){
int f[]=new int [n+1];
f[0]=0;f[1]=1;
for (int i=2; i<=n; i++){
f[i]=f[i-1]+f[i-2];
System.out.print("f["+i+"]="+f[i]);
System.out.println("\ta("+i+")="+a(i));

}
}
public static void main(String[] args)throws Exception{
Scanner input=new Scanner(System.in);
int n=input.nextInt();
f(n);
}
}

Related Posts Plugin for WordPress, Blogger...

熱門文章