Advertisement
Egonau

1.6-2

Jan 7th, 2023
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.51 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.         int num = sc.nextInt();
  9.         BigInteger f1 = BigInteger.ONE;
  10.         BigInteger f0 = BigInteger.ZERO;
  11.         if (num==0){ System.out.println(f0); }
  12.         else{
  13.             if (num==1){ System.out.println(f1); }
  14.             else{
  15.                 for (int i = 1;i<=num;++i) {
  16.                     BigInteger f = f0.add(f1);
  17.                     f0 = f1;
  18.                     f1 = f;
  19.                 }
  20.                 System.out.println(f0);
  21.             }
  22.         }
  23.     }
  24. }
  25.  
  26.  
  27.  
  28.  
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement