Cod sursa(job #1740856)

Utilizator BogauuuBogdan Ivancu Bogauuu Data 12 august 2016 13:18:28
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int zero(int x) {
    int prod = 5;
    int sum = 0;
    while (prod <= x) {
        sum += x/prod;
        prod *= 5;
    }
    return sum;
}

int p,st,dr,mid;

int main()
{
    fin >> p;
    st=1;
    dr=5*p;
    while (st<=dr){
        int mid=(st+dr)/2;
        if ( zero(mid) < p)
            st = mid+1;
        else
            dr = mid-1;
    }

    if (zero(st) == p)
        fout<<st;
    else
        fout<<-1;


    return 0;
}