Cod sursa(job #1997242)

Utilizator PopeangaMihneaPopeanga Mihnea- Stefan PopeangaMihnea Data 3 iulie 2017 19:27:53
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int n, p, st, dr, m, r;

int zero(int x)
{
    int nr=0;
    int p=5;
    while(x>=p)
    {
        nr=nr+(x/p);
        p=p*5;
    }
    return nr;
}

int main()
{
    fin>>p;
    if(p==0) fout<<"1"<<"\n";
    else
    {
        st=1; dr=p*5;
        r=-1;
        while(st<=dr)
        {
            m=(st+dr)/2;
            if(zero(m)==p)
            {
                r=m;
                dr=m-1;
            }
            else st=m+1;
        }
        fout<<r<<"\n";
    }
    return 0;
}