Cod sursa(job #2435346)
| Utilizator | Data | 3 iulie 2019 18:14:49 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.59 kb |
#include <fstream>
using namespace std;
ifstream ci ("fact.in");
ofstream co ("fact.out");
int zero (int n)
{
int sol=0;
while (n>0)
{
sol+=n/5;
n/=5;
}
return sol;
}
int main()
{
int p,n2=1;
ci >> p;
while (n2*2<=5*p)
{
n2*=2;
}
int sol=5*p+1;
for (int step=n2; step>0; step/=2)
{
if (sol-step>0 && zero(sol-step)>=p)
{
sol-=step;
}
}
if (zero(sol)>p)
{
co << "-1";
}
else
{
co << sol;
}
return 0;
}
