Cod sursa(job #1462774)

Utilizator greenday28stoienescu paul greenday28 Data 18 iulie 2015 22:48:29
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.52 kb
#include<fstream>
using namespace std;
long long nrzero(int x)
{
    int l,v=0;
    l=x;
    while(l>0)
    {
        v=v+l/5;
        l=l/5;
    }
    return v;
}
int main()
{
    ifstream in("fact.in");
    ofstream out("fact.out");
    int p,st,dr,med;
    in>>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)
    out<<st;
    else
        out<<-1;

}