Cod sursa(job #2892536)

Utilizator KakaDuuTurbut Sebastian KakaDuu Data 22 aprilie 2022 15:41:59
Problema Factorial Scor 15
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.35 kb
#include <fstream>
using namespace std;

int main() {
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    int n=1, p, i=1;
    fin >> p;
    while (p>0) {
        n = n*i;
        while (n%10 == 0)
            p--, n /= 10;
        n = n%10;
        i++;
    }
    if (!p)
        fout << i-1;
    else fout << -1;
    return 0;
}