Cod sursa(job #2142303)
| Utilizator | Data | 24 februarie 2018 21:56:45 | |
|---|---|---|---|
| Problema | Factorial | Scor | 15 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.69 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int pow5(int n)
{
long long s = 0;
while(n >= 5)
{
s=s + n/5;
n =n/5;
}
return s;
}
int main()
{
int a = 0;
long int c,b = 1000000000,p;
f>>p;
if(p == 0)
{
g<<1;
return 0;
}
while(a < b)
{
c = (a + b)/2;
if(pow5(c) >= p)
{
b = c;
}
else
{
a = c + 1;
}
}
if(pow5(c) != p)
g<<-1;
else
{
a = a - 5;
g<<a;
}
return 0;
}
