Cod sursa(job #2487185)

Utilizator NoobUserNameMatei Otniel NoobUserName Data 4 noiembrie 2019 10:30:42
Problema Factorial Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int n,p;
int zerouri(int x)
{
    int s=0,putere=5;
    while(x/putere)
    {
        s+=x/putere;
        putere*=5;
    }
    return s;
}
int main()
{
    int st=1,dr=500000000,mij,c;
    fin>>p;
    if(p==0)
        fout<<1;
    else
    {
        while(st<=dr)
        {
            mij=st+(dr-st)/2;
            if(p==zerouri(mij))
            {
                c=1;
                n=mij;
                break;
            }
            else if(p<zerouri(mij))
                dr=mij-1;
            else
                st=mij+1;
        }
        if(c==0)
            fout<<-1;
        else fout<<n-n%5;
    }
}