Cod sursa(job #1953397)

Utilizator VladTZYVlad Tiganila VladTZY Data 4 aprilie 2017 19:53:00
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
unsigned long long int l=1,r=1000000000,n,mij,x,p,sol=-1;
int test(int x)
{
    int z=5,t=0;
    while(x/z)
    {
        t=t+x/z;
        z=z*5;
    }
    return t;
}
int main()
{
    f>>p;
    while(l<=r)
    {
        mij=(l+r)/ 2;
        x=test(mij);
        if(x<p)
            l=mij+1;
        else
            if(x>p)
                r=mij-1;
            else
            {
                sol=mij;
                r=mij-1;
            }
    }
    g<<sol<<"\n";
}