Cod sursa(job #2052375)

Utilizator stefaniatudorTudor Stefania stefaniatudor Data 30 octombrie 2017 15:33:43
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>

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

int nrzero(int x)
{
    int 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)
    {

        mij=(x+y)/2;
        b=nrzero(mij);
        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;
}