Cod sursa(job #2618098)
| Utilizator | Data | 23 mai 2020 17:26:42 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.75 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n;
int nz(int n)
{
int x=0;
while(n>=5)
{
n/=5;
x+=n;
}
return x;
}
int caut(int x, int y)
{
int mijloc,aux;
if(x > y)
{
return 0;
}
mijloc = (x+y)/2;
aux = nz(mijloc);
if(aux==n)
{
return mijloc;
}
if(aux > n)
{
return caut(x, mijloc-1);
}
return caut(mijloc+1, y);
}
int main()
{
f>>n;
if(n==0)
{
g<<1;
}
else
{
int x = caut(0, n*5);
x-=x%5;
if(x==0)
{
x = -1;
}
g<<x;
}
return 0;
}
