Cod sursa(job #2418061)

Utilizator cyg_Alex_codegicianBarbu Alexandru cyg_Alex_codegician Data 3 mai 2019 13:02:19
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.47 kb
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
int nr_zero(int n)
{
    int nr=0,imp=n;
    while (imp!=0)
    {
        imp=imp/5;
        nr=nr+imp;
    }
    return nr;
}
int main()
{
    int p,st=1,dr=400000050,mij;
    fin >> p;
    while (st<dr)
    {
        mij=(st+dr)/2;
        if (nr_zero(mij)>=p) dr=mij;
        else st=mij+1;
    }
    if (nr_zero(st)==p) fout << st;
    else fout << -1;
}