Cod sursa(job #2379376)

Utilizator arosearose red arose Data 13 martie 2019 14:32:52
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <cstdio>

int nrDeZero(int x)
{
    if (x<5) return 0;
    return x/5+nrDeZero(x/5);
}
int main()
{
    FILE *f = fopen("fact.in", "r");
    FILE *fout = fopen("fact.out", "w");

    int P=0, out=0, corect=0;
    fscanf(f,"%d", &P);
    if (P==0) {
        fprintf(fout, "%d", 1); 
        return 0;
    }
    int high = P;
    int low = 0;
    while (low<=high)
    {
        int mid = low + (high-low)/2;
        int x = nrDeZero(mid*5);
        if (x==P) {
            fprintf(fout, "%d", mid*5);
            return 0;        
        } else if (x<P)
        {
            low = mid+1;
        } else {
            high = mid-1;
        }
    }
    fprintf(fout, "%d", -1); 

    
    return 0;
}