Cod sursa(job #1687110)
Utilizator | Data | 12 aprilie 2016 17:53:09 | |
---|---|---|---|
Problema | Factorial | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.6 kb |
#include<iostream>
#include<fstream>
#include<algorithm>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int zero(int x)
{
int p5 = 5;
int d = 0;
while (x/p5 != 0) {
d =d+ (x/p5);
p5=p5*5;
}
return d;
}
int P;
int main()
{
int last,first,mid;
f>>P;
first = 1; last = 6*P;
while (first<=last) {
mid = first + (last-first)/2;
if (zero(mid)>=P)
last = mid - 1;
else
first = mid + 1;
}
if(zero(first)==P)
g<<first;
else
g<<"-1";
}