Cod sursa(job #2076637)
| Utilizator | Data | 26 noiembrie 2017 21:25:21 | |
|---|---|---|---|
| Problema | Factorial | Scor | 5 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.64 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int caut(long v)
{
int zerouri = 1;
while(v)
{
zerouri+=(v/=5);
}
return zerouri;
}
long long P, N;
int main()
{
in >> P;
long left = 0;
long right = P*5;
long solutie = -1;
while(left<=right)
{
int mijloc = (left + right) / 2;
int posibil = caut(mijloc);
if(posibil>=P)
{
solutie = posibil;
right = mijloc - 1;
}
else left = mijloc + 1;
}
out << solutie;
return 0;
}
