Mai intai trebuie sa te autentifici.
Cod sursa(job #2203476)
Utilizator | Data | 12 mai 2018 14:11:42 | |
---|---|---|---|
Problema | Factorial | Scor | 90 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.73 kb |
#include <fstream>
#define i64 unsigned long long
using namespace std;
char const in [] = "fact.in";
char const out [] = "fact.out";
ifstream f (in);
ofstream g (out);
i64 p;
i64 lastzero (i64 val)
{
i64 power = 5 , searched = 0;
while(val / power)
{
searched += val / power;
power *= 5;
}
return searched;
}
int main()
{
f >> p;
i64 from , to , number , found = -1;
from = 1 ;
to = 1LL * (9223372036854775807 * 2);
while(from <= to)
{
i64 mid = (from + to) / 2;
number = lastzero (mid);
if(number >= p)
found = mid , to = mid - 1;
else
from = mid + 1;
}
g << found << '\n';
return 0;
}