Cod sursa(job #2052291)

Utilizator stefaniatudorTudor Stefania stefaniatudor Data 30 octombrie 2017 13:01:06
Problema Factorial Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>

using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");

int nrzero(int x)
{
    long long s=0;
    long long p=5;
    while(p<=x)
    {
        s=s+x/p;
        p=p*5;
    }
    return s;
}
int main()
{  int p,x=5,y=2000000000,mij,a,b,gasit=0;
    in>>p;
    if(p==0)
    {
        out<<1;
        return 0;
    }
    while(x<=y&&gasit==0)
    {
        a=nrzero(x);
        b=nrzero(y);
        mij=(x+y)/2;
        if(b==p)
            gasit=1;
        if(b<p)
            x=mij+1;
        else y=mij-1;
    }
    if(gasit==1) out<<mij-mij%5;
    if(gasit==0) out<<-1;

    return 0;
}