Cod sursa(job #1955189)

Utilizator ciutanpCiuta Andrei Calin ciutanp Data 5 aprilie 2017 20:49:43
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int l=1,r=1000000000,n,mij,x,p,sol=-1;
int verificationes(int x)
{
    int z=5,t=0;
    while(x/z)
    {
        t=t+x/z;
        z*=5;
    }
    return t;
}
int main()
{
    f>>p;
    while(l<=r)
    {
        mij=(l+r)/2;
        x=verificationes(mij);
        if(x<p)
            l=mij+1;
        else
            if(x>p)
            r=mij-1;
        else
        {
            sol=mij;
            r=mij-1;
        }
    }
    g<<sol;
}