Cod sursa(job #786642)

Utilizator andreiiiiPopa Andrei andreiiii Data 11 septembrie 2012 17:57:16
Problema Factorial Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

long long int n, st, dr, p, c, nrz;

long long int numarzerouri(int x)
{
    int i=0;
    while(x)
    {
        x/=5;
        i+=x;
    }
    return i;
}

int main()
{
fin>>p;
if(p==0) fout<<1;
else
{
st=0;
dr=1000000000LL;
n=1;
if(p>0){
while(n){  c=(st+dr)/2;
              nrz=numarzerouri(c);
              if(nrz==p&&st==dr) {n=st;break;}
              if(dr<st) {n=-1;break;}
    	      if(p>nrz) st=c+1;
                else dr=c-1;
               }
}
if(nrz==p&&st==dr) fout<<n;
if(dr<st) fout<<-1;
}

}