Cod sursa(job #3044)

Utilizator Sorin_IonutBYSorynyos Sorin_Ionut Data 20 decembrie 2006 15:48:51
Problema Factorial Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream.h>

long desc(long aux);

long nr,min=0,max=100000000,med,val;
int sw=1;

int main()
{
 ifstream fin("fact.in");
 fin>>nr;
 fin.close();

 ofstream fout("fact.out");
 if(nr==0)
  fout<<'1';
 else
 {
  while(sw)
  {
   med=(min+max)/2-((min+max)/2)%5;
   val=desc(med);
   if(val==nr)
   {
    sw=0;
    fout<<med;
    fout.close();
    return 0;
   }
   else
       if(val>nr)
        max=med-5;
       else
        min=med+5;
  }                                                             
 }
 fout<<"-1";
 fout.close();
 return 0;
}

long desc(long aux)
{
 long y=0,y1=aux;
 int sw=1;
 
 while(sw)
 {
  y1=y1/5;
  y=y+y1;
  if(y1==0)
   sw=0;
 }
return y;
}