Cod sursa(job #1965997)

Utilizator RaduVFVintila Radu-Florian RaduVF Data 14 aprilie 2017 20:11:27
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include    <iostream>
#include    <fstream>

using namespace std;

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

int zero(int x)
{
    int exp=5,t=0;
    while(x/exp!=0)
    {
        t+=x/exp;
        exp=exp*5;
    }
    return t;
}
int main()
{
    int p,st=1,dr=1000000000,mij,z,ok=0,s;
    fin>>p;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        z=zero(mij);
        if(z<p)
            st=mij+1;
        else if(z>p)
            dr=mij-1;
        else
        {
           s=mij;
           dr=mij-1;
        }
    }
   fout<<s;


    return 0;
}