Cod sursa(job #793279)
| Utilizator | Data | 2 octombrie 2012 14:05:39 | |
|---|---|---|---|
| Problema | Factorial | Scor | 85 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.5 kb |
#include <fstream>
#include <iostream>
using namespace std;
long long s = 1, d = 10000000000000000LL, m, p, k, j;
long long functie ( long long x )
{
k =0;
j = 5;
while ( j < x )
{
k += x/j;
j *= 5;
}
return k;
}
int main ( void )
{
ifstream fin ( "fact.in" );
ofstream fout ( "fact.out" );
fin >> p;
while ( s < d )
{
long long x = functie ( ( s + d ) / 2 );
if ( x >= p )
d = ( s + d ) / 2;
if ( x < p )
s = ( s + d ) / 2 + 1;
}
fout << s;
fin.close();
fout.close();
}
