Cod sursa(job #153963)

Utilizator cristiprgPrigoana Cristian cristiprg Data 10 martie 2008 20:36:25
Problema Factorial Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include"fstream"
using namespace std;

long cati5(long x);
long p;

int main()
{
    ifstream fin("fact.in");
    fin>>p;
    fin.close();
    
    ofstream fout("fact.out");
    
    long m=0,nr5=0;
    if(p==0)
       {
           fout<<"1";
           fout.close();
           return 0;
        }    
    
    while(nr5<p)
      {
          m+=5;
          nr5+=cati5(m);
          
          if(nr5==p)
            {    
	     fout<<m;
             fout.close();
             return 0;
             }
      }        
      
    fout<<"-1";
    fout.close();
    return 0;
}             
                   
                    
long cati5(long x)
{
    long contor=0;
    while(x!=1)
      {
          x/=5;
	  contor++;
	  if(x%5!=0)
	     return contor;
       }   
    return contor;
 }