Cod sursa(job #118771)

Utilizator gaby06Harja Gabriel gaby06 Data 27 decembrie 2007 19:58:35
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include<fstream.h>
#include<math.h>

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

unsigned long int a, b, p, i, x;
 double n, c;

int main()
{
	fin>>p;
	b= 5*p;
	int gasit = 0;
    do{
          c=(a+b)/2;
		  n = c/5;
		  i = 1;
		  x = pow(5,i);
		  while(x<=c)
		  {
		   n+=i-1;
		   x = pow(5,++i);
		  }
		  if(p == n)//5
          {gasit = 1;
            fout << c;     }
          else
              if(n>p)
                     b = c;
			  else
                  a=c;
              
       }while(!gasit && b>=a);
    
    
    
 fin.close();
 fout.close();
 return 0;   
}