Cod sursa(job #772159)

Utilizator RaileanuCristian Raileanu Raileanu Data 28 iulie 2012 14:33:13
Problema Factorial Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include<fstream>
using namespace std;

int zero(int x)
    { int putere=1, z=0;
      while (putere<=x)
          { putere*=5;
            z+=x/putere; }
      return z; };
      
int main () {
         ifstream f1("fact.in");
         ofstream f2("fact.out");
         
         int p,st,dr,m;
         
         f1>>p;
         st=1; dr=5*p;
         while (st<dr)
               {   m=st+(dr-st)/2;
                   if (p<= zero(m))
                      dr=m-1;
                      else st=m+1; }
         if (zero(st)==p)
            f2<<st;
            else f2<<-1;
         f1.close();
         f2.close();
         return 0; }