Cod sursa(job #287602)

Utilizator mihaionlyMihai Jiplea mihaionly Data 24 martie 2009 23:21:40
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#include <math.h>
using namespace std;
#define dim 100000100
typedef unsigned long long tip;
tip a,b,c,p,i,fn;
bool ok=false;
ifstream ef("fact.in");
ofstream g("fact.out");
tip get(tip c)
 {
 tip k=0,j,cn=c;
 while(cn%5==0)
  {
  cn/=5;
  k++;
  }
 k+=c/5;
 return k;
 }
int main()
 {
 ef>>p;
 if(p==0)
  {
  g<<"1";
  return 0;
  }
 a=0;
 b=dim;
 while(a<b&&!ok)
  {
  c=(a+b)/2-(((a+b)/2)%5);
  fn=get(c); //get(c) returneaza zerourile pe care le are la sfarsit c!
  if(fn==p)
   {
   ok=true;
   i=c;
   }
  else if(fn<p)
   a=c+1;
  else
   b=c-1;
  }
 if(ok)
  g<<i;
 else if(fn>p)
  g<<"-1";
 return 0;         
 }