Cod sursa(job #2701057)

Utilizator ionut98Bejenariu Ionut Daniel ionut98 Data 29 ianuarie 2021 18:46:41
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include<fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");

int main(){
    //reprezinta exact cate zerouri vrem sa avem la finalul lui n!
    long p;
    f >> p;

    long n = p*4;
    long cnt = 0;

    while(cnt < p){
        //contorul pt zerouri;
        cnt = 0;
        long copie_n = n;
        while(copie_n != 0){
            copie_n /= 5;
            cnt += copie_n;
        }
        n++;
    }

    if(p == 0){
        g << 1;
    }
    else if(cnt != p){
        g << -1;
    }
    else{
        g << n-1;
    }
    return 0;
}