Cod sursa(job #2611385)

Utilizator AlexnolifeAlexandru Ica Alexnolife Data 6 mai 2020 19:50:10
Problema Factorial Scor 35
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <cstdlib>
#include <fstream>
#include <iostream>

auto main() noexcept -> int
{
    std::ifstream f{ "fact.in" };
    std::ofstream g{ "fact.out" };

    int num{ 0 };
    int count{ 0 };

    f >> num;

    if(num == 0) {
        g << '1' << std::endl;
        return EXIT_SUCCESS;
    }

    for(int i = 5;; i += 5) {
        int j = i;

        while(j % 10 == 0) {
            ++count;
            j /= 10;
        }

        while(j % 5 == 0) {
            ++count;
            j /= 5;
        }

        if(count > num) {
            g << "-1" << std::endl;
            return EXIT_SUCCESS;
        }
        if(count == num) {
            g << i << std::endl;
            return EXIT_SUCCESS;
        }
    }
}