Cod sursa(job #779940)

Utilizator slyfer12Damian Alexandru slyfer12 Data 19 august 2012 15:56:35
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <fstream>
#include <math.h>
using namespace std;

int numZero(int x){
  int k=0,q=1;
    while(x/pow(5,q)){
       k+=x/pow(5,q);
       q++;
    }
   return k;
}
int main()
{long p,k;
   ifstream f("fact.in");
   ofstream g("fact.out");
   f>>p;
   f.close();
   k=2*p;
        if(p<numZero(k)){
         while(numZero(k)){
          k--;
         }
        }else {if(p>numZero(k))
          while(p!=numZero(k)){
            k++;
          }
        }
     if(!p)
     g<<1;
     else{if(p==numZero(k))
     g<<k;
     else
     g<<-1;}
     g.close();
    return 0;
}