Cod sursa(job #2748541)

Utilizator Andrei_TudorAndrei Tudor Andrei_Tudor Data 1 mai 2021 13:03:55
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
#include <cmath>
using namespace std;

int f(int x){
    int p = 5, k = 0;
    while(x / p > 0){
        k = k + x / p;
        p *= 5;
    }
    return k;
}

ifstream cin("factorial.in");
ofstream cout("factorial.out");
int main()
{
    int p, k, x = 0;
    cin >> p;
    if(p == 0){
        cout << 1;
    }
    else {
        k = sqrt(p);
        x = k;
        while(f(x) < p){
            x += k;
        }
        x -= k;
        while(f(x) < p){
            x ++;
        }
        if(f(x) > p){
            cout << "-1";
        }
        else {
            cout << x;
        }
    }
    return 0;
}