Cod sursa(job #1368211)

Utilizator ceciliamariciucCecilia Mariciuc ceciliamariciuc Data 2 martie 2015 15:11:09
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <fstream>

using namespace std;

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

int main ()
{int p,gasit,nr;
long long s,d,m,cm;
fin>>p ;
d=1000000000;s=1;
gasit=0;
while(s<=d&&gasit==0)
  {m=(s+d)/2;
   cm=m;
   nr=0;
   while(cm!=0)
        {nr=nr+cm/5 ;
         cm=cm/5;
        }
    if(nr==p)
        {gasit=1;
         if(p==0) m=1;
         else m=m-m%5;
        }
    else if (nr>p) d=m-1;
         else s=m+1;
   }
    if(gasit==1) fout<<m;
    else fout<<-1;

fin.close();
fout.close();
    return 0;
}