Cod sursa(job #2052166)

Utilizator sabinastratstrat sabina sabinastrat Data 30 octombrie 2017 09:52:27
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.8 kb
#include <fstream>

using namespace std;

ifstream f("fact.in");
ofstream g("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,a=nrzero(x),b,c=nrzero(y),gasit=0,mij;
    f>>p;
    if(p==0)
    {
        g<<1;
        return 0;

    }

    while(x<=y && gasit==0)
    {
        mij=(x+y)/2;
        b=nrzero(mij);
        if(b==mij)
        {
            gasit=1;
        }
        if(b<p)
        {
            x=mij+1;
            a=nrzero(x);

        }
        if(b>p)
        {
            y=mij-1;
            c=nrzero(y);
        }
    }
    if(gasit==1)
        g<<mij-mij%5;
    else g<<-1;
    return 0;
}