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
herrDeng網內搜尋
自訂搜尋
Ads
2011年6月2日 星期四
訂閱:
張貼留言 (Atom)
熱門文章
-
教育部為提昇全民資安素養與電腦防護能力,本部於101年9月5日至11月5日舉辦「全民資安素養自我評量」活動,請在活動期間內踴躍上網檢測資訊安全素養認知程度,並有機會參與抽獎,詳情請參閱活動網站(網址: https://isafe.moe.edu.tw/event
-
url="https://www.twse.com.tw/exchangeReport/STOCK_DAY?response=json&date=20220330&stockNo=2330"
-
先說明一下這是後知後覺的解答,所謂後知就是股票價格已知存在陣列(清單),當然就要用迴圈練習,雙迴圈暴力解需時O(n**2),當然不用,採python單一迴圈解答「最佳股票的買賣時機#LeetCode 121 Best Time to Buy and Sell Stock」,解...
-
你會用C的算子sizeof?
-
Python C++使用字串find迴圈速解Leetcode 2490 Circular Sentence C++ & Python都有字串的find,用法都類似 split=s.find(' ', split+1)能找到s從index=split+1開...
-
Python CPP heap priority queue速解L eetcode 2530. Maximal Score After Applying K Operations heap/priority queue是重要的資料結構,無論是C++的std::priority_q...
20 則留言:
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
張貼留言