Cod sursa(job #2549896)

Utilizator iustin2004Bolota Iustin iustin2004 Data 18 februarie 2020 08:57:55
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int putere(int x)
{
    int z=0,y;
    y=5;
    while(x>=y)
    {
        z=z+x/y;
        y=y*5;
    }
    return z;
}
int p,i,st,dr,mij,nrz;
int main()
{
    fin>>p;
    if(p==0)
    {
        fout<<1;
        return 0;
    }
    st=5;
    dr=2000000000;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        nrz=putere(mij);
        if(nrz==p)
        {
            fout<<mij-mij%5;
            return 0;
        }
        else
            if(nrz<p)
            st=mij+1;
            else
                dr=mij-1;
    }
    fout<<-1;
    return 0;
}