Cod sursa(job #3139137)

Utilizator AndPitAndreeaPiticar AndPit Data 25 iunie 2023 16:19:57
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int main(){
    int x;
    f >> x;
    if (x == 0){
        g << 1;
        return 0;
    }
    int i = 1;
    int nr = 0, cnt;
    while(true){
        ++nr;
        cnt = i;
        while (cnt % 5 == 0) {
            cnt /= 5;
            ++nr;
        }
        if (nr == x){
            g << i * 5;
            return 0;
        }
        else if (nr > x){
            g << -1;
            return 0;
        }
        ++i;
    }
    return 0;
}