Cod sursa(job #1466872)

Utilizator Mihai9Oniga Mihai Mihai9 Data 31 iulie 2015 11:15:46
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.51 kb
#include<fstream>
using namespace std;
long long nrzero(int x)
{
    int l,v=0;
    l=x;
    while(l>0)
    {
        v+=l/5;
        l=l/5;
    }
    return v;
}
int main()
{
    ifstream fin("fact.in");
    ofstream fout("fact.out");
    int p,st,dr,med;
    fin>>p;
    st=1;
    dr=500000000;
    while(st<=dr)
    {
        med=(st+dr)/2;
        if(nrzero(med)<p)
            st=med+1;
        else
          dr=med-1;
    }
    if(nrzero(st)==p)
    fout<<st;
    else
    fout<<-1;
}