UVA 10579 - Fibonacci Numbers

UVA Sep 01, 2020

Problem PDF

Solution:

package mypkg;
import java.math.BigInteger;
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
      Scanner in = new Scanner (System.in);
      int n;
      while(in.hasNext())
      {
          n=in.nextInt();
          BigInteger a=BigInteger.ONE;
          BigInteger b=BigInteger.ONE;
          BigInteger sum=BigInteger.ZERO;
          while(n>=3)
          {
              sum=a.add(b);
              b=a;
              a=sum;
              n--;
          }
       System.out.println(sum);
      }
    }

}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/10579/Main.java

Tags

Shipu Ahamed

CSPO® | Partly Product, Project Manager and Partly Software Engineer.

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.