Cod sursa(job #412478)

Utilizator al_flAlexandru Flavian al_fl Data 5 martie 2010 18:50:55
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include<fstream>
#include<iostream>
#include<math.h>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n;
unsigned long long p;
long nrz1( long c )
{
     long x = 0;
     while( c )
     {
            x += c/5;
            c /= 5;
     }
     return x;
}
int bin()
{
    int low,high,mid;
       low = 1;
       high = 10000000000LL;
       while (low < high) {
           mid = low + ((high - low) / 2);
           if (nrz1(mid)< p)
               low = mid + 1;
           else
                high = mid;
       }
       if ((low < 10000000000LL) && (nrz1(low) == p))
           return low;
       else
           return -1;
}

int main()
{
    f>>p;
    g<<bin()<<endl;
    f.close();
    g.close();
    return 0;
}