返回列表 發帖
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;


  4. public class Ch02 {
  5.     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  6.         Ch02() throws Exception, Exception
  7.         {
  8.                 long x[]=new long[90],input;
  9.                 input=Integer.parseInt(br.readLine());
  10.                 x[0]=0;
  11.                 x[1]=1;
  12.                 for(int i=2; i<x.length; i++)
  13.                         x[i]=x[i-1]+x[i-2];               
  14.                 System.out.println(x[(int) input]);
  15.         }
  16.         public static void main(String[] args) throws Exception {
  17.                 long start=System.currentTimeMillis();
  18.                 new Ch02();
  19.                 System.out.println(System.currentTimeMillis()-start+"ms");
  20.         }
  21. }
複製代碼

TOP

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;


  4. public class Ch02 {
  5.     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  6.         Ch02() throws Exception, Exception
  7.         {
  8.                 int input;
  9.                 input=Integer.parseInt(br.readLine());
  10.                 System.out.println(f(input));
  11.         }
  12.         int f(int n)
  13.         {
  14.                 if(n<2)
  15.                         return n;
  16.                 else
  17.                         return f(n-2)+f(n-1);
  18.         }
  19.         public static void main(String[] args) throws Exception {
  20.                 long start=System.currentTimeMillis();
  21.                 new Ch02();
  22.                 long end=System.currentTimeMillis();
  23.                 System.out.println((end-start)+"ms");
  24.         }
  25. }
複製代碼

TOP

返回列表