Cod sursa(job #3329180)

Utilizator EdwardLGGavril-Lainer Edward-Mihai EdwardLG Data 12 decembrie 2025 09:14:06
Problema Nunta Scor 0
Compilator java Status done
Runda Arhiva de probleme Marime 0.87 kb
import java.io.*;
import java.math.BigInteger;

public class nunta {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new FileReader("nunta.in"));
        int N = Integer.parseInt(br.readLine().trim());
        br.close();

        BigInteger f1 = BigInteger.ONE;  
        BigInteger f2 = BigInteger.ONE;  

        if (N == 1) {
            writeOutput(BigInteger.ONE);
            return;
        }

        BigInteger f = BigInteger.ZERO;
        for (int i = 3; i <= N + 1; i++) {
            f = f1.add(f2);
            f1 = f2;
            f2 = f;
        }

        writeOutput(f2);
    }

    private static void writeOutput(BigInteger result) throws Exception {
        PrintWriter pw = new PrintWriter(new FileWriter("nunta.out"));
        pw.println(result);
        pw.close();
    }
}